Skip to content

Commit b9d7666

Browse files
committed
Replaced nlunit-test with pw_unit_test in src/lib/shell/
1 parent 80b2f61 commit b9d7666

File tree

3 files changed

+13
-58
lines changed

3 files changed

+13
-58
lines changed

src/lib/shell/tests/BUILD.gn

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
17-
import("//build_overrides/nlunit_test.gni")
1817

1918
import("${chip_root}/build/chip/chip_test_suite.gni")
2019

21-
chip_test_suite_using_nltest("tests") {
20+
chip_test_suite("tests") {
2221
output_name = "libTestShell"
2322

2423
test_sources = [
@@ -31,7 +30,5 @@ chip_test_suite_using_nltest("tests") {
3130
public_deps = [
3231
"${chip_root}/src/lib/core",
3332
"${chip_root}/src/lib/shell",
34-
"${chip_root}/src/lib/support:testing_nlunit",
35-
"${nlunit_test_root}:nlunit-test",
3633
]
3734
}

src/lib/shell/tests/TestShellStreamerStdio.cpp

+6-27
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
* limitations under the License.
1616
*/
1717

18-
#include <nlunit-test.h>
18+
#include <gtest/gtest.h>
1919

2020
#include <lib/shell/Engine.h>
2121
#include <lib/support/CodeUtils.h>
22-
#include <lib/support/UnitTestRegistration.h>
22+
2323

2424
#include <inttypes.h>
2525
#include <stdarg.h>
@@ -48,7 +48,7 @@ static const struct test_streamer_vector test_vector_streamer_out[] = {
4848
// Unit tests
4949
// =================================
5050

51-
static void TestStreamer_Output(nlTestSuite * inSuite, void * inContext)
51+
TEST(TestShellStreamerStdio, TestStreamer_Output)
5252
{
5353
int numOfTestVectors = ArraySize(test_vector_streamer_out);
5454
int numOfTestsRan = 0;
@@ -64,29 +64,8 @@ static void TestStreamer_Output(nlTestSuite * inSuite, void * inContext)
6464

6565
num_chars = streamer_write(streamer_get(), output, strlen(output));
6666
// Let's assume that all our output lengths fit in ssize_t.
67-
NL_TEST_ASSERT(inSuite, num_chars == static_cast<ssize_t>(strlen(output)));
67+
EXPECT_EQ(num_chars, static_cast<ssize_t>(strlen(output)));
6868
numOfTestsRan++;
6969
}
70-
NL_TEST_ASSERT(inSuite, numOfTestsRan > 0);
71-
}
72-
73-
/**
74-
* Test Suite. It lists all the test functions.
75-
*/
76-
static const nlTest sTests[] = {
77-
78-
NL_TEST_DEF("Test Shell: TestStreamer_Output", TestStreamer_Output),
79-
80-
NL_TEST_SENTINEL()
81-
};
82-
83-
int TestStreamerStdio()
84-
{
85-
nlTestSuite theSuite = { "Test Shell: Streamer", &sTests[0], nullptr, nullptr };
86-
87-
// Run test suite against one context.
88-
nlTestRunner(&theSuite, nullptr);
89-
return nlTestRunnerStats(&theSuite);
90-
}
91-
92-
CHIP_REGISTER_TEST_SUITE(TestStreamerStdio)
70+
EXPECT_GT(numOfTestsRan, 0);
71+
}

src/lib/shell/tests/TestShellTokenizeLine.cpp

+6-27
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
* limitations under the License.
1616
*/
1717

18-
#include <nlunit-test.h>
18+
#include <gtest/gtest.h>
1919

2020
#include <lib/support/CodeUtils.h>
21-
#include <lib/support/UnitTestRegistration.h>
21+
2222

2323
// Include entire C++ file to have access to functions-under-test
2424
// such as TokenizeLine despite them being declared within an anonymous namespace.
@@ -99,7 +99,7 @@ static const struct test_shell_vector test_vector_shell_tokenizer[] = {
9999
// Unit tests
100100
// =================================
101101

102-
static void TestShell_Tokenizer(nlTestSuite * inSuite, void * inContext)
102+
TEST(TestShellTokenizeLine, TestShell_Tokenizer)
103103
{
104104
int numOfTestVectors = ArraySize(test_vector_shell_tokenizer);
105105
int numOfTestsRan = 0;
@@ -115,34 +115,13 @@ static void TestShell_Tokenizer(nlTestSuite * inSuite, void * inContext)
115115
char * argv[TEST_SHELL_MAX_TOKENS];
116116
int argc = TokenizeLine(line, argv, TEST_SHELL_MAX_TOKENS);
117117

118-
NL_TEST_ASSERT(inSuite, argc == test_params->argc);
118+
EXPECT_EQ(argc, test_params->argc);
119119

120120
for (int i = 0; i < argc; i++)
121121
{
122-
NL_TEST_ASSERT(inSuite, strcmp(argv[i], test_params->argv[i]) == 0);
122+
EXPECT_EQ(strcmp(argv[i], test_params->argv[i]), 0);
123123
}
124124
numOfTestsRan++;
125125
}
126-
NL_TEST_ASSERT(inSuite, numOfTestsRan > 0);
126+
EXPECT_GT(numOfTestsRan, 0);
127127
}
128-
129-
/**
130-
* Test Suite. It lists all the test functions.
131-
*/
132-
static const nlTest sTests[] = {
133-
134-
NL_TEST_DEF("Test Shell: TestShell_Tokenizer", TestShell_Tokenizer),
135-
136-
NL_TEST_SENTINEL()
137-
};
138-
139-
int TestShellTokenizeLine()
140-
{
141-
nlTestSuite theSuite = { "Test Shell: MainLoop", &sTests[0], nullptr, nullptr };
142-
143-
// Run test suite against one context.
144-
nlTestRunner(&theSuite, nullptr);
145-
return nlTestRunnerStats(&theSuite);
146-
}
147-
148-
CHIP_REGISTER_TEST_SUITE(TestShellTokenizeLine)

0 commit comments

Comments
 (0)