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