TEST(shell, start) { char test_chars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', '\n', 0 }; char *p = test_chars; s_handle = shell_create(s_pool, POOL_SIZE, stub_putc, stub_getc, stub_exec, NULL); TEST_ASSERT_NOT_NULL( s_handle ); TEST_ASSERT_UNLESS( shell_set_prompt(s_handle, "") ); pthread_create(&s_thread, NULL, thread_shell, NULL); while (*p) { while (s_txc); s_txc = *p++; } pthread_mutex_lock(&s_mutex); pthread_cond_wait(&s_cv, &s_mutex); pthread_mutex_unlock(&s_mutex); TEST_ASSERT_EQUAL_STRING_LEN(test_chars, s_rxbuf, strlen(test_chars)); /* excludes new line code */ TEST_ASSERT_EQUAL_STRING_LEN(test_chars, s_result_line, strlen(test_chars) - 1); TEST_ASSERT_UNLESS( shell_destroy(s_handle) ); s_txc = '\n'; pthread_join(s_thread, NULL); }
TEST(shell, hook) { char test_chars[] = { 'a', '\n', 0 }; char *p; // OK hook s_error = 1; p = test_chars; s_handle = shell_create(s_pool, POOL_SIZE, stub_putc, stub_getc, stub_exec_ok, stub_post_hook); TEST_ASSERT_NOT_NULL( s_handle ); pthread_create(&s_thread, NULL, thread_shell, NULL); while (*p) { while (s_txc); s_txc = *p++; } pthread_mutex_lock(&s_mutex); pthread_cond_wait(&s_cv, &s_mutex); pthread_mutex_unlock(&s_mutex); TEST_ASSERT_EQUAL_INT32( 0, s_error ); TEST_ASSERT_UNLESS( shell_destroy(s_handle) ); s_txc = '\n'; pthread_join(s_thread, NULL); // NG hook s_error = 0; p = test_chars; s_handle = shell_create(s_pool, POOL_SIZE, stub_putc, stub_getc, stub_exec_ng, stub_post_hook); TEST_ASSERT_NOT_NULL( s_handle ); pthread_create(&s_thread, NULL, thread_shell, NULL); while (*p) { while (s_txc); s_txc = *p++; } pthread_mutex_lock(&s_mutex); pthread_cond_wait(&s_cv, &s_mutex); pthread_mutex_unlock(&s_mutex); TEST_ASSERT_EQUAL_INT32( -1, s_error ); TEST_ASSERT_UNLESS( shell_destroy(s_handle) ); s_txc = '\n'; pthread_join(s_thread, NULL); }
TEST(shell, destroy) { s_handle = shell_create(s_pool, POOL_SIZE, stub_putc, stub_getc, stub_exec, NULL); TEST_ASSERT_NOT_NULL( s_handle ); TEST_ASSERT_UNLESS( shell_destroy(s_handle) ); TEST_ASSERT( shell_start(s_handle) ); }
celix_status_t shell_create(bundle_context_pt context_ptr, shell_service_pt *shell_service_ptr) { celix_status_t status = CELIX_SUCCESS; if (!context_ptr || !shell_service_ptr) { status = CELIX_ILLEGAL_ARGUMENT; } if (status == CELIX_SUCCESS) { *shell_service_ptr = calloc(1, sizeof(**shell_service_ptr)); if (!*shell_service_ptr) { status = CELIX_ENOMEM; } } if (status == CELIX_SUCCESS) { (*shell_service_ptr)->shell = calloc(1, sizeof(*(*shell_service_ptr)->shell)); if (!(*shell_service_ptr)->shell) { status = CELIX_ENOMEM; } } if (status == CELIX_SUCCESS) { (*shell_service_ptr)->shell->bundle_context_ptr = context_ptr; (*shell_service_ptr)->shell->command_name_map_ptr = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); (*shell_service_ptr)->shell->command_reference_map_ptr = hashMap_create(NULL, NULL, NULL, NULL); (*shell_service_ptr)->getCommands = shell_getCommands; (*shell_service_ptr)->getCommandDescription = shell_getCommandDescription; (*shell_service_ptr)->getCommandUsage = shell_getCommandUsage; (*shell_service_ptr)->getCommandReference = shell_getCommandReference; (*shell_service_ptr)->executeCommand = shell_executeCommand; status = logHelper_create(context_ptr, &(*shell_service_ptr)->shell->logHelper); } if (status != CELIX_SUCCESS) { shell_destroy(shell_service_ptr); } return status; }
void uninit_server_shell(void) { shell_destroy(g_shell); g_shell = 0; }