Skip to content

Commit

Permalink
fix(developer): combine tests from #11910 and this PR
Browse files Browse the repository at this point in the history
  • Loading branch information
markcsinclair committed Jul 4, 2024
1 parent 7efd46f commit 82d041a
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions developer/src/kmcmplib/tests/gtest-kmx_u16-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,22 @@
#include "../../../../common/include/km_types.h"

class kmx_u16_Test : public testing::Test {
protected:
kmx_u16_Test() {}
~kmx_u16_Test() override {}
void SetUp() override {}
void TearDown() override {}
protected:
kmx_u16_Test() {}
~kmx_u16_Test() override {}
void SetUp() override {}
void TearDown() override {}
};

TEST_F(kmx_u16_Test, u16chr_test) {
KMX_WCHAR str[LINESIZE];
KMX_WCHAR str[LINESIZE];

u16cpy(str, u"abc");
EXPECT_EQ(1, u16chr(str, 'b') - str); // in string
u16cpy(str, u"abc");
EXPECT_EQ(1, u16chr(str, 'b') - str); // in string
u16cpy(str, u"abc");
EXPECT_EQ(NULL, u16chr(str, 'd')); // not in string
EXPECT_EQ(NULL, u16chr(str, 'd')); // not in string
u16cpy(str, u"abc");
EXPECT_EQ(3, u16chr(str, '\0') - str); // locate null terminator
}

TEST_F(kmx_u16_Test, u16tok_ch_test) {
EXPECT_TRUE(true);
}

// KMX_WCHAR * u16tok(KMX_WCHAR* p, const KMX_WCHAR* delim, KMX_WCHAR** ctx)
TEST_F(kmx_u16_Test, u16tok_delim_test) {
KMX_WCHAR str[LINESIZE];
PKMX_WCHAR ctx = NULL;

// no string, no context
EXPECT_EQ(NULL, u16tok(nullptr, u"", &ctx));

// delimited string
u16cpy(str, u"abc|def");
EXPECT_EQ(str, u16tok(str, u"|", &ctx));
EXPECT_EQ(0, u16cmp(u"abc", str));
EXPECT_EQ(0, u16cmp(u"def", ctx));
EXPECT_EQ(3, u16chr(str, '\0') - str); // locate null terminator
}

TEST_F(kmx_u16_Test, u16tok_char_delim) {
Expand All @@ -62,6 +43,7 @@ TEST_F(kmx_u16_Test, u16tok_char_delim) {
TEST_F(kmx_u16_Test, u16tok_str_delim) {
// For string delimiter: KMX_WCHAR * u16tok(KMX_WCHAR* p, const KMX_WCHAR* ch, KMX_WCHAR** ctx) ;

KMX_WCHAR str[LINESIZE];
KMX_WCHAR *ctx = nullptr;
EXPECT_EQ(nullptr, u16tok(nullptr, u" ", &ctx));

Expand All @@ -75,6 +57,15 @@ TEST_F(kmx_u16_Test, u16tok_str_delim) {
KMX_WCHAR buffer_space[128] = u" ";
EXPECT_EQ(nullptr, u16tok(buffer_space, u" ", &ctx));
EXPECT_EQ(nullptr, u16tok(nullptr, u" ", &ctx));

// no string, no context
EXPECT_EQ(nullptr, u16tok(nullptr, u"", &ctx));

// delimited string
u16cpy(str, u"abc|def");
EXPECT_EQ(str, u16tok(str, u"|", &ctx));
EXPECT_EQ(0, u16cmp(u"abc", str));
EXPECT_EQ(0, u16cmp(u"def", ctx));
}

TEST_F(kmx_u16_Test, u16tok_str_compare_to_strtok) {
Expand Down

0 comments on commit 82d041a

Please sign in to comment.