3 * Copyright (c) 2020 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include "TestShell.h"
20 #include <shell/shell.h>
21 #include <support/CodeUtils.h>
22 #include <support/UnitTestRegistration.h>
31 using namespace chip::Shell;
32 using namespace chip::Logging;
34 // =================================
36 // =================================
38 struct test_streamer_vector
43 static const struct test_streamer_vector test_vector_streamer_out[] = {
44 { .output = "prompt>\n" }, { .output = "T123 " }, { .output = "T456\n" }, { .output = "T789 " }, { .output = "T10\n" },
47 // =================================
49 // =================================
51 static void TestStreamer_Output(nlTestSuite * inSuite, void * inContext)
53 int numOfTestVectors = ArraySize(test_vector_streamer_out);
54 int numOfTestsRan = 0;
55 const struct test_streamer_vector * test_params;
60 for (int vectorIndex = 0; vectorIndex < numOfTestVectors; vectorIndex++)
62 test_params = &test_vector_streamer_out[vectorIndex];
63 output = test_params->output;
65 num_chars = streamer_write(streamer_get(), output, strlen(output));
66 // 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)));
70 NL_TEST_ASSERT(inSuite, numOfTestsRan > 0);
74 * Test Suite. It lists all the test functions.
76 static const nlTest sTests[] = {
78 NL_TEST_DEF("Test Streamer: TestStreamer_Output", TestStreamer_Output),
83 int TestStreamerStdio(void)
85 nlTestSuite theSuite = { "CHIP Streamer tests", &sTests[0], nullptr, nullptr };
87 // Run test suit againt one context.
88 nlTestRunner(&theSuite, nullptr);
89 return nlTestRunnerStats(&theSuite);
92 CHIP_REGISTER_TEST_SUITE(TestStreamerStdio)