Skip to content

Commit

Permalink
Replaced nlunit-test with pw_unit_test in src/lib/shell/
Browse files Browse the repository at this point in the history
  • Loading branch information
mbknust committed Apr 19, 2024
1 parent 80b2f61 commit b9d7666
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 58 deletions.
5 changes: 1 addition & 4 deletions src/lib/shell/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/nlunit_test.gni")

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

chip_test_suite_using_nltest("tests") {
chip_test_suite("tests") {
output_name = "libTestShell"

test_sources = [
Expand All @@ -31,7 +30,5 @@ chip_test_suite_using_nltest("tests") {
public_deps = [
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/shell",
"${chip_root}/src/lib/support:testing_nlunit",
"${nlunit_test_root}:nlunit-test",
]
}
33 changes: 6 additions & 27 deletions src/lib/shell/tests/TestShellStreamerStdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* limitations under the License.
*/

#include <nlunit-test.h>
#include <gtest/gtest.h>

#include <lib/shell/Engine.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/UnitTestRegistration.h>


#include <inttypes.h>
#include <stdarg.h>
Expand Down Expand Up @@ -48,7 +48,7 @@ static const struct test_streamer_vector test_vector_streamer_out[] = {
// Unit tests
// =================================

static void TestStreamer_Output(nlTestSuite * inSuite, void * inContext)
TEST(TestShellStreamerStdio, TestStreamer_Output)
{
int numOfTestVectors = ArraySize(test_vector_streamer_out);
int numOfTestsRan = 0;
Expand All @@ -64,29 +64,8 @@ static void TestStreamer_Output(nlTestSuite * inSuite, void * inContext)

num_chars = streamer_write(streamer_get(), output, strlen(output));
// Let's assume that all our output lengths fit in ssize_t.
NL_TEST_ASSERT(inSuite, num_chars == static_cast<ssize_t>(strlen(output)));
EXPECT_EQ(num_chars, static_cast<ssize_t>(strlen(output)));
numOfTestsRan++;
}
NL_TEST_ASSERT(inSuite, numOfTestsRan > 0);
}

/**
* Test Suite. It lists all the test functions.
*/
static const nlTest sTests[] = {

NL_TEST_DEF("Test Shell: TestStreamer_Output", TestStreamer_Output),

NL_TEST_SENTINEL()
};

int TestStreamerStdio()
{
nlTestSuite theSuite = { "Test Shell: Streamer", &sTests[0], nullptr, nullptr };

// Run test suite against one context.
nlTestRunner(&theSuite, nullptr);
return nlTestRunnerStats(&theSuite);
}

CHIP_REGISTER_TEST_SUITE(TestStreamerStdio)
EXPECT_GT(numOfTestsRan, 0);
}
33 changes: 6 additions & 27 deletions src/lib/shell/tests/TestShellTokenizeLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* limitations under the License.
*/

#include <nlunit-test.h>
#include <gtest/gtest.h>

#include <lib/support/CodeUtils.h>
#include <lib/support/UnitTestRegistration.h>


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

static void TestShell_Tokenizer(nlTestSuite * inSuite, void * inContext)
TEST(TestShellTokenizeLine, TestShell_Tokenizer)
{
int numOfTestVectors = ArraySize(test_vector_shell_tokenizer);
int numOfTestsRan = 0;
Expand All @@ -115,34 +115,13 @@ static void TestShell_Tokenizer(nlTestSuite * inSuite, void * inContext)
char * argv[TEST_SHELL_MAX_TOKENS];
int argc = TokenizeLine(line, argv, TEST_SHELL_MAX_TOKENS);

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

for (int i = 0; i < argc; i++)
{
NL_TEST_ASSERT(inSuite, strcmp(argv[i], test_params->argv[i]) == 0);
EXPECT_EQ(strcmp(argv[i], test_params->argv[i]), 0);
}
numOfTestsRan++;
}
NL_TEST_ASSERT(inSuite, numOfTestsRan > 0);
EXPECT_GT(numOfTestsRan, 0);
}

/**
* Test Suite. It lists all the test functions.
*/
static const nlTest sTests[] = {

NL_TEST_DEF("Test Shell: TestShell_Tokenizer", TestShell_Tokenizer),

NL_TEST_SENTINEL()
};

int TestShellTokenizeLine()
{
nlTestSuite theSuite = { "Test Shell: MainLoop", &sTests[0], nullptr, nullptr };

// Run test suite against one context.
nlTestRunner(&theSuite, nullptr);
return nlTestRunnerStats(&theSuite);
}

CHIP_REGISTER_TEST_SUITE(TestShellTokenizeLine)

0 comments on commit b9d7666

Please sign in to comment.