Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced nlunit-test with pw_unit_test in src/lib/shell/ #33066

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
]
}
30 changes: 4 additions & 26 deletions src/lib/shell/tests/TestShellStreamerStdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
* 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 +47,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 +63,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);
EXPECT_GT(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)
32 changes: 5 additions & 27 deletions src/lib/shell/tests/TestShellTokenizeLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
* 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 +98,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 +114,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)
1 change: 1 addition & 0 deletions src/test_driver/openiotsdk/unit-tests/test_components.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
accesstest
PlatformTests
TestShell
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ SecureChannelTests
SetupPayloadTests
SupportTests
SystemLayerTests
TestShell
TransportLayerTests
UserDirectedCommissioningTests
Loading