5#include "testing/testing.h"
22 map.
add(
"hello"_ustr, 1);
35 map.
add(
"world"_ustr.ref(), 2);
36 map.
add_as(
"world"_ustr.ref(), 3);
47 map.
add_as(
"world"_ustr.string(), 2);
62 EXPECT_EQ(
"test"_ustr, std::string(
"test"));
63 EXPECT_EQ(std::string(
"test"),
"test"_ustr);
66 EXPECT_EQ(
"test"_ustr, std::string_view(
"test"));
67 EXPECT_EQ(std::string_view(
"test"),
"test"_ustr);
70TEST(ustring, UniqueCorrectness)
72 static const char *from_static_literal =
"unique_correctness_98765";
74 const std::string to_chars_result = std::to_string(98765);
75 const std::string from_to_chars = std::string(
"unique_correctness_") + to_chars_result;
77 const std::string from_concatenation = std::string(
"unique_correctness_9876") +
"5";
79 const UString a(from_static_literal);
81 const UString c(from_concatenation);
92 const UString default_constructed;
94 const UString from_std_string{std::string()};
95 const UString from_ustr_literal =
""_ustr;
100 EXPECT_STREQ(from_literal.
c_str(),
"");
107 EXPECT_EQ(from_literal, from_std_string);
108 EXPECT_EQ(from_literal, from_ustr_literal);
111 EXPECT_EQ(default_constructed, from_literal);
116 const std::string long_a(500,
'a');
117 const std::string long_b = std::string(300,
'b') + std::string(300,
'c');
138 const UString from_literal_op =
"literal_operator_test_string"_ustr;
139 const UString from_ctor(
"literal_operator_test_string");
140 const UString from_std_string(std::string(
"literal_operator_test_string"));
148 const UString from_literal_op_again =
"literal_operator_test_string"_ustr;
155 map.
add(
"hashing_test_alpha"_ustr, 1);
156 map.
add(
"hashing_test_beta"_ustr, 2);
168 constexpr int64_t total = 20000;
172 for (
const int64_t i : sub_range) {
176 const std::string matching = std::string(
"concurrency_test_shared_string");
177 results[i] =
UString(matching);
182 const std::string number_str = std::to_string(i);
188 const char *shared_ptr =
nullptr;
191 if (shared_ptr ==
nullptr) {
192 shared_ptr = results[i].c_str();
195 EXPECT_EQ(results[i].c_str(), shared_ptr);
199 const std::string number_str = std::to_string(i);
205TEST(ustring, ConcurrentSameNewString)
209 constexpr int THREADS_NUM = 8;
210 constexpr int STRINGS_NUM = 200;
214 strings.
append(
"concurrent_same_new_string_" + std::to_string(i));
218 for (
const int thread_i :
IndexRange(THREADS_NUM)) {
222 std::atomic<int> ready_num = 0;
224 for (
const int thread_i :
IndexRange(THREADS_NUM)) {
225 threads.
append(std::thread([&, thread_i]() {
227 ready_num.fetch_add(1);
228 while (ready_num.load() < THREADS_NUM) {
231 results[thread_i][i] =
UString(strings[i]);
235 for (std::thread &
thread : threads) {
240 const UString &expected = results[0][i];
243 for (
const int thread_i :
IndexRange(THREADS_NUM)) {
245 EXPECT_EQ(results[thread_i][i], expected);
void reinitialize(const int64_t new_size)
constexpr IndexRange()=default
bool add(const Key &key, const Value &value)
const Value & lookup(const Key &key) const
bool add_as(ForwardKey &&key, ForwardValue &&...value)
const Value & lookup_as(const ForwardKey &key) const
constexpr StringRefNull()
const char * c_str() const
void append(const T &value)
#define EXPECT_TRUE(result)
TEST(any_virtual, DefaultConstructor)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void BLI_task_scheduler_init(bool use_flush_denormals_to_zero=true)