From b3e72c7944a738fe9201c406332cbcd878df65e3 Mon Sep 17 00:00:00 2001 From: Naoto Yamaguchi Date: Thu, 15 Apr 2021 10:48:30 +0000 Subject: Initial commit for AGL cluster api library This source code is AGL instrument cluster common API library. Currently, this source code is missing author information, license and other. Will be add by author. Author: Nozomu Abe (nozo_abe@nippon-seiki.co.jp) Committed by Naoto Yamaguchi. Signed-off-by: Naoto Yamaguchi --- test/client_test/client_test_init_term.c | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 test/client_test/client_test_init_term.c (limited to 'test/client_test/client_test_init_term.c') diff --git a/test/client_test/client_test_init_term.c b/test/client_test/client_test_init_term.c new file mode 100644 index 0000000..00f2f13 --- /dev/null +++ b/test/client_test/client_test_init_term.c @@ -0,0 +1,69 @@ +#include +#include +#include + +#include + +#include + +#include "client_test_common.h" + +// OK case. Calling the APIs of Init and Term while the server is already started. +static void TestInitAndTermOK(void) +{ + CU_ASSERT(clusterInit() == true); + CU_ASSERT(clusterTerm() == true); +} + +// NG case. Call the API of Init function twice. +static void TestInitAndTermNG1(void) +{ + CU_ASSERT(clusterInit() == true); + CU_ASSERT(clusterInit() == false); + CU_ASSERT(clusterTerm() == true); +} + +// NG case. Call the API of Term function twice. +static void TestInitAndTermNG2(void) +{ + CU_ASSERT(clusterInit() == true); + CU_ASSERT(clusterTerm() == true); + CU_ASSERT(clusterTerm() == false); +} + +// NG case. Call the API of Term only. +static void TestInitAndTermNG3(void) +{ + CU_ASSERT(clusterTerm() == false); +} + +// NG case. Server is not ready. +static void TestInitAndTermNG4(void) +{ + pid_t child; + + stopDummyServer(); + CU_ASSERT(clusterInit() == false); + CU_ASSERT(clusterTerm() == false); + + if ((child = fork()) < 0) { + fprintf(stderr, "%s:%d Failed to fork() : %d\n", __FILE__, __LINE__, child); + exit(EXIT_FAILURE); + } + + startDummyServer(child); + connectToDummyServer(); +} + +void SetTestSuiteInitAndTerm(void) +{ + CU_pSuite testSuite; + + testSuite = CU_add_suite("InitAndTerm", NULL, NULL); + CU_add_test(testSuite, "InitAndTerm_OK", TestInitAndTermOK); + CU_add_test(testSuite, "InitAndTerm_NG_1", TestInitAndTermNG1); + CU_add_test(testSuite, "InitAndTerm_NG_2", TestInitAndTermNG2); + CU_add_test(testSuite, "InitAndTerm_NG_3", TestInitAndTermNG3); + CU_add_test(testSuite, "InitAndTerm_NG_4", TestInitAndTermNG4); +} + -- cgit 1.2.3-korg