2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2016-02-06 19:09:44 +01:00
|
|
|
|
2025-07-31 19:46:54 +02:00
|
|
|
#include <gtest/gtest.h>
|
2016-02-06 19:09:44 +01:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/string.h"
|
2016-02-06 19:09:44 +01:00
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
/* ******** Tests for string_printf() ******** */
|
|
|
|
|
|
|
|
|
|
TEST(util_string_printf, no_format)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_printf("foo bar");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ("foo bar", str);
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_printf, int_number)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_printf("foo %d bar", 314);
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ("foo 314 bar", str);
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_printf, float_number_default_precision)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_printf("foo %f bar", 3.1415);
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ("foo 3.141500 bar", str);
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_printf, float_number_custom_precision)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_printf("foo %.1f bar", 3.1415);
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ("foo 3.1 bar", str);
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ******** Tests for string_printf() ******** */
|
|
|
|
|
|
|
|
|
|
TEST(util_string_iequals, empty_a)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const bool equals = string_iequals("", "foo");
|
2016-02-06 19:09:44 +01:00
|
|
|
EXPECT_FALSE(equals);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_iequals, empty_b)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const bool equals = string_iequals("foo", "");
|
2016-02-06 19:09:44 +01:00
|
|
|
EXPECT_FALSE(equals);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_iequals, same_register)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const bool equals = string_iequals("foo", "foo");
|
2016-02-06 19:09:44 +01:00
|
|
|
EXPECT_TRUE(equals);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_iequals, different_register)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const bool equals = string_iequals("XFoo", "XfoO");
|
2016-02-06 19:09:44 +01:00
|
|
|
EXPECT_TRUE(equals);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ******** Tests for string_split() ******** */
|
|
|
|
|
|
|
|
|
|
TEST(util_string_split, empty)
|
|
|
|
|
{
|
|
|
|
|
vector<string> tokens;
|
|
|
|
|
string_split(tokens, "");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(tokens.size(), 0);
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_split, only_spaces)
|
|
|
|
|
{
|
|
|
|
|
vector<string> tokens;
|
|
|
|
|
string_split(tokens, " \t\t \t");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(tokens.size(), 0);
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_split, single)
|
|
|
|
|
{
|
|
|
|
|
vector<string> tokens;
|
|
|
|
|
string_split(tokens, "foo");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(tokens.size(), 1);
|
|
|
|
|
EXPECT_EQ(tokens[0], "foo");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_split, simple)
|
|
|
|
|
{
|
|
|
|
|
vector<string> tokens;
|
|
|
|
|
string_split(tokens, "foo a bar b");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(tokens.size(), 4);
|
|
|
|
|
EXPECT_EQ(tokens[0], "foo");
|
|
|
|
|
EXPECT_EQ(tokens[1], "a");
|
|
|
|
|
EXPECT_EQ(tokens[2], "bar");
|
|
|
|
|
EXPECT_EQ(tokens[3], "b");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_split, multiple_spaces)
|
|
|
|
|
{
|
|
|
|
|
vector<string> tokens;
|
|
|
|
|
string_split(tokens, " \t foo \ta bar b\t ");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(tokens.size(), 4);
|
|
|
|
|
EXPECT_EQ(tokens[0], "foo");
|
|
|
|
|
EXPECT_EQ(tokens[1], "a");
|
|
|
|
|
EXPECT_EQ(tokens[2], "bar");
|
|
|
|
|
EXPECT_EQ(tokens[3], "b");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ******** Tests for string_replace() ******** */
|
|
|
|
|
|
|
|
|
|
TEST(util_string_replace, empty_haystack_and_other)
|
|
|
|
|
{
|
2024-12-26 17:53:59 +01:00
|
|
|
string str;
|
2016-02-06 19:09:44 +01:00
|
|
|
string_replace(str, "x", "");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(str, "");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_replace, empty_haystack)
|
|
|
|
|
{
|
2024-12-26 17:53:59 +01:00
|
|
|
string str;
|
2016-02-06 19:09:44 +01:00
|
|
|
string_replace(str, "x", "y");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(str, "");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_replace, empty_other)
|
|
|
|
|
{
|
|
|
|
|
string str = "x";
|
|
|
|
|
string_replace(str, "x", "");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(str, "");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_replace, long_haystack_empty_other)
|
|
|
|
|
{
|
|
|
|
|
string str = "a x b xxc";
|
|
|
|
|
string_replace(str, "x", "");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(str, "a b c");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_replace, long_haystack)
|
|
|
|
|
{
|
|
|
|
|
string str = "a x b xxc";
|
|
|
|
|
string_replace(str, "x", "FOO");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(str, "a FOO b FOOFOOc");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ******** Tests for string_endswith() ******** */
|
|
|
|
|
|
|
|
|
|
TEST(util_string_endswith, empty_both)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const bool endswith = string_endswith("", "");
|
2016-02-06 19:09:44 +01:00
|
|
|
EXPECT_TRUE(endswith);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_endswith, empty_string)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const bool endswith = string_endswith("", "foo");
|
2016-02-06 19:09:44 +01:00
|
|
|
EXPECT_FALSE(endswith);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_endswith, empty_end)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const bool endswith = string_endswith("foo", "");
|
2016-02-06 19:09:44 +01:00
|
|
|
EXPECT_TRUE(endswith);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_endswith, simple_true)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const bool endswith = string_endswith("foo bar", "bar");
|
2016-02-06 19:09:44 +01:00
|
|
|
EXPECT_TRUE(endswith);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_endswith, simple_false)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const bool endswith = string_endswith("foo bar", "foo");
|
2016-02-06 19:09:44 +01:00
|
|
|
EXPECT_FALSE(endswith);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ******** Tests for string_strip() ******** */
|
|
|
|
|
|
|
|
|
|
TEST(util_string_strip, empty)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_strip("");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(str, "");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_strip, only_spaces)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_strip(" ");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(str, "");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_strip, no_spaces)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_strip("foo bar");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(str, "foo bar");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_strip, with_spaces)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_strip(" foo bar ");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(str, "foo bar");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ******** Tests for string_remove_trademark() ******** */
|
|
|
|
|
|
|
|
|
|
TEST(util_string_remove_trademark, empty)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_remove_trademark("");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(str, "");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_remove_trademark, no_trademark)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_remove_trademark("foo bar");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(str, "foo bar");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_remove_trademark, only_tm)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_remove_trademark("foo bar(TM) zzz");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(str, "foo bar zzz");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_remove_trademark, only_r)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_remove_trademark("foo bar(R) zzz");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(str, "foo bar zzz");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_remove_trademark, both)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_remove_trademark("foo bar(TM)(R) zzz");
|
2017-02-03 11:35:34 +01:00
|
|
|
EXPECT_EQ(str, "foo bar zzz");
|
2016-02-06 19:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
2017-06-08 12:15:24 +02:00
|
|
|
TEST(util_string_remove_trademark, both_space)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_remove_trademark("foo bar(TM) (R) zzz");
|
2017-06-08 12:15:24 +02:00
|
|
|
EXPECT_EQ(str, "foo bar zzz");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_remove_trademark, both_space_around)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_remove_trademark("foo bar (TM) (R) zzz");
|
2017-06-08 12:15:24 +02:00
|
|
|
EXPECT_EQ(str, "foo bar zzz");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_remove_trademark, trademark_space_suffix)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_remove_trademark("foo bar (TM)");
|
2017-06-08 12:15:24 +02:00
|
|
|
EXPECT_EQ(str, "foo bar");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_remove_trademark, trademark_space_middle)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_remove_trademark("foo bar (TM) baz");
|
2017-06-08 12:15:24 +02:00
|
|
|
EXPECT_EQ(str, "foo bar baz");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_remove_trademark, r_space_suffix)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_remove_trademark("foo bar (R)");
|
2017-06-08 12:15:24 +02:00
|
|
|
EXPECT_EQ(str, "foo bar");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(util_string_remove_trademark, r_space_middle)
|
|
|
|
|
{
|
2024-12-29 17:32:00 +01:00
|
|
|
const string str = string_remove_trademark("foo bar (R) baz");
|
2017-06-08 12:15:24 +02:00
|
|
|
EXPECT_EQ(str, "foo bar baz");
|
|
|
|
|
}
|
|
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
/* ******** Tests for string_startswith() ******** */
|
|
|
|
|
|
|
|
|
|
TEST(string_startswith, basic)
|
|
|
|
|
{
|
|
|
|
|
EXPECT_TRUE(string_startswith("", ""));
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(string_startswith("", "World"));
|
|
|
|
|
EXPECT_TRUE(string_startswith("Hello", ""));
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(string_startswith("Hello", "World"));
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(string_startswith("Hello", "Hello"));
|
|
|
|
|
EXPECT_TRUE(string_startswith("Hello", "He"));
|
|
|
|
|
EXPECT_TRUE(string_startswith("Hello", "H"));
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(string_startswith("Hello", "e"));
|
|
|
|
|
EXPECT_FALSE(string_startswith("Hello", "HelloWorld"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(string_endswith, basic)
|
|
|
|
|
{
|
|
|
|
|
EXPECT_TRUE(string_endswith("", ""));
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(string_endswith("", "World"));
|
|
|
|
|
EXPECT_TRUE(string_endswith("Hello", ""));
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(string_endswith("Hello", "World"));
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(string_endswith("Hello", "Hello"));
|
|
|
|
|
EXPECT_TRUE(string_endswith("Hello", "lo"));
|
|
|
|
|
EXPECT_TRUE(string_endswith("Hello", "o"));
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(string_endswith("Hello", "e"));
|
|
|
|
|
EXPECT_FALSE(string_endswith("Hello", "WorldHello"));
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-06 19:09:44 +01:00
|
|
|
CCL_NAMESPACE_END
|