2018-06-11 06:26:57 +00:00
|
|
|
void DqnFixedString_Test()
|
|
|
|
{
|
|
|
|
LOG_HEADER();
|
|
|
|
{
|
2018-06-25 10:54:38 +00:00
|
|
|
DqnFixedString<512> str = DQN_SLICE("hello world");
|
2018-06-11 06:26:57 +00:00
|
|
|
DQN_ASSERT(DqnStr_Cmp(str.str, "hello world") == 0);
|
|
|
|
|
|
|
|
Log(Status::Ok, "Copy constructor DqnSlice<char>");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
DqnFixedString<512> zero = {};
|
2018-06-25 10:54:38 +00:00
|
|
|
DqnFixedString<512> str = DQN_SLICE("hello world");
|
2018-06-11 06:26:57 +00:00
|
|
|
str = zero;
|
|
|
|
DQN_ASSERT(str.len == 0 && str.str[0] == 0);
|
|
|
|
|
2018-06-25 10:54:38 +00:00
|
|
|
DqnSlice<char const> helloSlice = DQN_SLICE("hello");
|
2018-06-11 06:26:57 +00:00
|
|
|
str = helloSlice;
|
|
|
|
DQN_ASSERT(DqnStr_Cmp(str.str, "hello") == 0);
|
|
|
|
|
|
|
|
Log(Status::Ok, "Copy constructor (DqnFixedString<>)");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-06-25 10:54:38 +00:00
|
|
|
DqnFixedString<512> str = DQN_SLICE("hello world");
|
2018-06-11 06:26:57 +00:00
|
|
|
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
2018-06-29 08:07:54 +00:00
|
|
|
DQN_ASSERTM(DqnStr_Cmp(str.str, "hello sailor") == 0, "Result: %s", str.str);
|
2018-06-11 06:26:57 +00:00
|
|
|
|
|
|
|
Log(Status::Ok, "Sprintf");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
2018-06-25 10:54:38 +00:00
|
|
|
DqnFixedString<512> str = DQN_SLICE("hello world");
|
2018-06-11 06:26:57 +00:00
|
|
|
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
2018-06-25 10:54:38 +00:00
|
|
|
str += DQN_SLICE(".end");
|
2018-07-06 15:10:43 +00:00
|
|
|
DQN_ASSERTM(DqnStr_Cmp(str.str, "hello sailor.end") == 0, "Result: %s", str.str);
|
2018-06-11 06:26:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-06-25 10:54:38 +00:00
|
|
|
DqnFixedString<512> str = DQN_SLICE("hello world");
|
2018-06-11 06:26:57 +00:00
|
|
|
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
|
|
|
DQN_ASSERT(str.SprintfAppend(" %d, %d", 100, 200));
|
|
|
|
DQN_ASSERT(DqnStr_Cmp(str.str, "hello sailor 100, 200") == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Log(Status::Ok, "Concatenation, operator +=, SprintfAppend");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
DqnFixedString<512> str;
|
|
|
|
str = "hello big world";
|
|
|
|
DQN_ASSERT(DqnStr_Cmp(str.str, "hello big world") == 0);
|
|
|
|
str = DqnFixedString<512>("goodbye", DQN_CHAR_COUNT("goodbye"));
|
|
|
|
DQN_ASSERT(DqnStr_Cmp(str.str, "goodbye") == 0);
|
|
|
|
|
|
|
|
Log(Status::Ok, "Copy constructor (char const *str, int len)");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-06-25 10:54:38 +00:00
|
|
|
DqnFixedString<512> str = DQN_SLICE("hello world");
|
2018-06-11 06:26:57 +00:00
|
|
|
DQN_ASSERT(str.Sprintf("hello %s", "sailor"));
|
2018-06-25 10:54:38 +00:00
|
|
|
str = str + " end" + DQN_SLICE(" of");
|
2018-06-11 06:26:57 +00:00
|
|
|
DQN_ASSERT(DqnStr_Cmp(str.str, "hello sailor end of") == 0);
|
|
|
|
|
|
|
|
Log(Status::Ok, "Operator +");
|
|
|
|
}
|
2018-07-06 15:10:43 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
DqnFixedString<512> str = "localhost";
|
|
|
|
str.SprintfAppend(":%d", 16832);
|
|
|
|
str += "/json_rpc";
|
|
|
|
DQN_ASSERT(str.len == 24 && DqnStr_Cmp("localhost:16832/json_rpc", str.str) == 0);
|
|
|
|
|
|
|
|
Log(Status::Ok, "Copy constructor, sprintf, operator +=");
|
|
|
|
}
|
2018-06-11 06:26:57 +00:00
|
|
|
}
|