Blender  V3.3
asset_test.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 
4 #include "BKE_asset.h"
5 
6 #include "BLI_uuid.h"
7 
8 #include "DNA_asset_types.h"
9 
10 #include "testing/testing.h"
11 
12 namespace blender::bke::tests {
13 
14 TEST(AssetMetadataTest, set_catalog_id)
15 {
16  AssetMetaData meta;
17  const bUUID uuid = BLI_uuid_generate_random();
18 
19  /* Test trivial values. */
21  EXPECT_TRUE(BLI_uuid_is_nil(meta.catalog_id));
22  EXPECT_STREQ("", meta.catalog_simple_name);
23 
24  /* Test simple situation where the given short name is used as-is. */
25  BKE_asset_metadata_catalog_id_set(&meta, uuid, "simple");
26  EXPECT_TRUE(BLI_uuid_equal(uuid, meta.catalog_id));
27  EXPECT_STREQ("simple", meta.catalog_simple_name);
28 
29  /* Test white-space trimming. */
30  BKE_asset_metadata_catalog_id_set(&meta, uuid, " Govoriš angleško? ");
31  EXPECT_STREQ("Govoriš angleško?", meta.catalog_simple_name);
32 
33  /* Test length trimming to 63 chars + terminating zero. */
34  constexpr char len66[] = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20";
35  constexpr char len63[] = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1";
36  BKE_asset_metadata_catalog_id_set(&meta, uuid, len66);
37  EXPECT_STREQ(len63, meta.catalog_simple_name);
38 
39  /* Test length trimming happens after white-space trimming. */
40  constexpr char len68[] =
41  " \
42  000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20 ";
43  BKE_asset_metadata_catalog_id_set(&meta, uuid, len68);
44  EXPECT_STREQ(len63, meta.catalog_simple_name);
45 
46  /* Test length trimming to 63 bytes, and not 63 characters. ✓ in UTF-8 is three bytes long. */
47  constexpr char with_utf8[] =
48  "00010203040506✓0708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20";
49  BKE_asset_metadata_catalog_id_set(&meta, uuid, with_utf8);
50  EXPECT_STREQ("00010203040506✓0708090a0b0c0d0e0f101112131415161718191a1b1c1d",
51  meta.catalog_simple_name);
52 }
53 
54 } // namespace blender::bke::tests
void BKE_asset_metadata_catalog_id_set(struct AssetMetaData *asset_data, bUUID catalog_id, const char *catalog_simple_name)
void BKE_asset_metadata_catalog_id_clear(struct AssetMetaData *asset_data)
Definition: asset.cc:104
bool BLI_uuid_is_nil(bUUID uuid)
Definition: uuid.cc:76
bUUID BLI_uuid_generate_random(void)
Definition: uuid.cc:21
bool BLI_uuid_equal(bUUID uuid1, bUUID uuid2)
Definition: uuid.cc:81
TEST(action_groups, ReconstructGroupsWithReordering)
Definition: action_test.cc:17
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
char catalog_simple_name[64]
struct bUUID catalog_id
Universally Unique Identifier according to RFC4122.