This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/blenkernel/intern/asset_test.cc
Campbell Barton c434782e3a File headers: SPDX License migration
Use a shorter/simpler license convention, stops the header taking so
much space.

Follow the SPDX license specification: https://spdx.org/licenses

- C/C++/objc/objc++
- Python
- Shell Scripts
- CMake, GNUmakefile

While most of the source tree has been included

- `./extern/` was left out.
- `./intern/cycles` & `./intern/atomic` are also excluded because they
  use different header conventions.

doc/license/SPDX-license-identifiers.txt has been added to list SPDX all
used identifiers.

See P2788 for the script that automated these edits.

Reviewed By: brecht, mont29, sergey

Ref D14069
2022-02-11 09:14:36 +11:00

55 lines
2.0 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2020 Blender Foundation. All rights reserved. */
#include "BKE_asset.h"
#include "BLI_uuid.h"
#include "DNA_asset_types.h"
#include "testing/testing.h"
namespace blender::bke::tests {
TEST(AssetMetadataTest, set_catalog_id)
{
AssetMetaData meta;
const bUUID uuid = BLI_uuid_generate_random();
/* Test trivial values. */
BKE_asset_metadata_catalog_id_clear(&meta);
EXPECT_TRUE(BLI_uuid_is_nil(meta.catalog_id));
EXPECT_STREQ("", meta.catalog_simple_name);
/* Test simple situation where the given short name is used as-is. */
BKE_asset_metadata_catalog_id_set(&meta, uuid, "simple");
EXPECT_TRUE(BLI_uuid_equal(uuid, meta.catalog_id));
EXPECT_STREQ("simple", meta.catalog_simple_name);
/* Test white-space trimming. */
BKE_asset_metadata_catalog_id_set(&meta, uuid, " Govoriš angleško? ");
EXPECT_STREQ("Govoriš angleško?", meta.catalog_simple_name);
/* Test length trimming to 63 chars + terminating zero. */
constexpr char len66[] = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20";
constexpr char len63[] = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1";
BKE_asset_metadata_catalog_id_set(&meta, uuid, len66);
EXPECT_STREQ(len63, meta.catalog_simple_name);
/* Test length trimming happens after white-space trimming. */
constexpr char len68[] =
" \
000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20 ";
BKE_asset_metadata_catalog_id_set(&meta, uuid, len68);
EXPECT_STREQ(len63, meta.catalog_simple_name);
/* Test length trimming to 63 bytes, and not 63 characters. ✓ in UTF-8 is three bytes long. */
constexpr char with_utf8[] =
"00010203040506✓0708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20";
BKE_asset_metadata_catalog_id_set(&meta, uuid, with_utf8);
EXPECT_STREQ("00010203040506✓0708090a0b0c0d0e0f101112131415161718191a1b1c1d",
meta.catalog_simple_name);
}
} // namespace blender::bke::tests