static void dl_prepend_append_test(void) { printsln((String)__func__); List ac, ex; ac = dl_create(); dl_append(ac, 1); dl_append(ac, 2); dl_append(ac, 3); ex = dl_create(); dl_prepend(ex, 3); dl_prepend(ex, 2); dl_prepend(ex, 1); dl_check_within(ac, ex); l_free(ac); l_free(ex); }
uint8 dl_update(DL_LIST **node, uint16 new_tag, void *new_object) { DL_LIST *new_node; uint8 result = DL_BAD_ARGUMENT; if (node != NULL) { result = dl_create(&new_node, new_tag, new_object); if (result == DL_SUCCESS) { if (*node != NULL) { dl_insert_before(*node, new_node); dl_delete(*node); *node = new_node; } else { *node = new_node; } } } return result; }
uint8 dl_add_last(DL_LIST **list, uint16 tag, void *object) { DL_LIST *last_node; DL_LIST *new_node; uint8 result = DL_BAD_ARGUMENT; if (list != NULL) { result = dl_create(&new_node, tag, object); if (result == DL_SUCCESS) { if (*list == NULL) { *list = new_node; } else { last_node = dl_get_last(*list); dl_insert_after(last_node, new_node); } } } return result; }
static void dl_fill_test(void) { printsln((String)__func__); List ex, ac; ac = dl_repeat(3, 0); dl_fill(ac, -1); ex = dl_of_string("-1, -1, -1"); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_repeat(2, 0); dl_fill(ac, 2); ex = dl_of_string("2, 2"); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_repeat(0, 0); dl_fill(ac, 2); ex = dl_create(); dl_check_within(ac, ex); l_free(ac); l_free(ex); }
static void dl_fn_test(void) { printsln((String)__func__); List ac, ex; ac = dl_fn(3, two_d_plus_1, 0); ex = dl_of_string("1, 3, 5"); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_fn(4, two_d_plus_1, 0); ex = dl_of_string("1, 3, 5, 7"); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_fn(1, two_d_plus_1, 0); ex = dl_of_string("1"); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_fn(0, two_d_plus_1, 0); ex = dl_create(); dl_check_within(ac, ex); l_free(ac); l_free(ex); }
List dl_of_il(List list) { assert_argument_not_null(list); il_assert_element_size(list); List result = dl_create(); for (IntListNode *node = list->first; node != NULL; node = node->next) { dl_append(result, node->value); } return result; }
List dl_map_state(List list, DoubleIntDoubleAnyToDouble f, double x, Any state) { assert_function_not_null(f); assert_argument_not_null(list); dl_assert_element_size(list); List result = dl_create(); int i = 0; for (DoubleListNode *node = list->first; node != NULL; node = node->next, i++) { dl_append(result, f(node->value, i, x, state)); } return result; }
List dl_fn(int n, IntDoubleToDouble init, double x) { assert_function_not_null(init); if (n < 0) { printf("%s: length cannot be negative (is %d)\n", __func__, n); exit(EXIT_FAILURE); } List result = dl_create(); for (int i = 0; i < n; i++) { dl_append(result, init(i, x)); } return result; }
/** * Produce an IN_DELETE/IN_CREATE notifications pair for an overwritten file. * Reopen a watch for the overwritten file. * * This function is used as a callback and is invoked from the dep-list * routines. * * @param[in] udata A pointer to user data (#handle_context). * @param[in] path File name of the overwritten file. * @param[in] inode Inode number of the overwritten file. **/ static void handle_overwritten (void *udata, const char *path, ino_t inode) { assert (udata != NULL); handle_context *ctx = (handle_context *) udata; assert (ctx->wrk != NULL); assert (ctx->w != NULL); assert (ctx->be != NULL); int i; for (i = 0; i < ctx->wrk->sets.length; i++) { watch *wi = ctx->wrk->sets.watches[i]; if (wi && (strcmp (wi->filename, path) == 0) && wi->parent == ctx->w) { if (watch_reopen (wi) == -1) { /* I dont know, what to do */ /* Not a very beautiful way to remove a single dependency */ dep_list *dl = dl_create (wi->filename, wi->inode); worker_remove_many (ctx->wrk, ctx->w, dl, 0); dl_shallow_free (dl); } else { uint32_t cookie = inode & 0x00000000FFFFFFFF; int event_len = 0; struct inotify_event *ev; ev = create_inotify_event (ctx->w->fd, IN_DELETE, cookie, path, &event_len); if (ev != NULL) { bulk_write (ctx->be, ev, event_len); free (ev); } else { perror_msg ("Failed to create an IN_DELETE event (*) for %s", path); } ev = create_inotify_event (ctx->w->fd, IN_CREATE, cookie, path, &event_len); if (ev != NULL) { bulk_write (ctx->be, ev, event_len); free (ev); } else { perror_msg ("Failed to create an IN_CREATE event (*) for %s", path); } } break; } } }
List dl_filter_state(List list, DoubleIntDoubleAnyToBool predicate, double x, Any state) { assert_function_not_null(predicate); assert_argument_not_null(list); dl_assert_element_size(list); List result = dl_create(); int i = 0; for (DoubleListNode *node = list->first; node != NULL; node = node->next, i++) { if (predicate(node->value, i, x, state)) { dl_append(result, node->value); } } return result; }
/** * Produce an IN_MOVED_FROM/IN_MOVED_TO notifications pair for a replaced file. * Also stops wathing on the replaced file. * * This function is used as a callback and is invoked from the dep-list * routines. * * @param[in] udata A pointer to user data (#handle_context). * @param[in] from_path File name of the source file. * @param[in] from_inode Inode number of the source file. * @param[in] to_path File name of the replaced file. * @param[in] to_inode Inode number of the replaced file. **/ static void handle_replaced (void *udata, const char *from_path, ino_t from_inode, const char *to_path, ino_t to_inode) { assert (udata != NULL); handle_context *ctx = (handle_context *) udata; assert (ctx->wrk != NULL); assert (ctx->w != NULL); assert (ctx->be != NULL); uint32_t cookie = from_inode & 0x00000000FFFFFFFF; int event_len = 0; struct inotify_event *ev; ev = create_inotify_event (ctx->w->fd, IN_MOVED_FROM, cookie, from_path, &event_len); if (ev != NULL) { bulk_write (ctx->be, ev, event_len); free (ev); } else { perror_msg ("Failed to create an IN_MOVED_FROM event (*) for %s", from_path); } ev = create_inotify_event (ctx->w->fd, IN_MOVED_TO, cookie, to_path, &event_len); if (ev != NULL) { bulk_write (ctx->be, ev, event_len); free (ev); } else { perror_msg ("Failed to create an IN_MOVED_TO event (*) for %s", to_path); } int i; for (i = 1; i < ctx->wrk->sets.length; i++) { watch *iw = ctx->wrk->sets.watches[i]; if (iw && iw->parent == ctx->w && strcmp (to_path, iw->filename) == 0) { dep_list *dl = dl_create (iw->filename, iw->inode); worker_remove_many (ctx->wrk, ctx->w, dl, 0); dl_shallow_free (dl); break; } } }
List dl_choose(List list, DoubleIntDoubleToDoubleOption f, double x) { assert_function_not_null(f); assert_argument_not_null(list); dl_assert_element_size(list); List result = dl_create(); int i = 0; for (DoubleListNode *node = list->first; node != NULL; node = node->next, i++) { DoubleOption op = f(node->value, i, x); if (!op.none) { dl_append(result, op.some); } } return result; }
uint8 dl_add_after(DL_LIST **node, uint16 tag, void *object) { DL_LIST *new_node; uint8 result = DL_BAD_ARGUMENT; if (node != NULL) { result = dl_create(&new_node, tag, object); if (result == DL_SUCCESS) { if (*node == NULL) { *node = new_node; } else { dl_insert_after(*node, new_node); } } } return result; }
static void dl_of_string_test(void) { printsln((String)__func__); List ac, ex; ac = dl_of_string("1, 2, 3, 4, 5, 6"); ex = dl_range(1, 7, 1); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string(" 1, 2, 3, 4, 5, 6 "); ex = dl_range(1, 7, 1); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string("1xx2asdfs3"); ex = dl_range(1, 4, 1); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string("y1xx2asdfs3x"); ex = dl_range(1, 4, 1); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string("-3, -2, -1, 0, 1"); ex = dl_range(-3, 2, 1); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string(" -3, -2, -1 "); ex = dl_range(-3, 0, 1); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string(".1 -20. -3.5 1e5 -1.2e4 -1.2e-4"); ex = dl_create(); dl_append(ex, 0.1); dl_append(ex, -20.0); dl_append(ex, -3.5); dl_append(ex, 1e5); dl_append(ex, -1.2e4); dl_append(ex, -1.2e-4); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string("-.1.-2.-.3.-"); ex = dl_create(); dl_append(ex, -0.1); dl_append(ex, -2.0); dl_append(ex, -0.3); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string("---.1.----2.----.3.----"); ex = dl_create(); dl_append(ex, -0.1); dl_append(ex, -2.0); dl_append(ex, -0.3); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string(""); ex = dl_create(); dl_check_within(ac, ex); l_free(ac); l_free(ex); }
int main( int argc, char *argv[] ) { dl_head_typ *pusr; /* A list of slv_clt_typ structures, * which contain client information, * and channels for communications. */ slv_db_typ *pdb; /* The variable list, which contains * data, the sizes, and a list trigger * clients for each variable. */ comm_clt_typ *psvc_clt; /* Client calls are received here. */ comm_clt_typ *pdb_clt; /* This points to the current client.*/ db_data_typ recv_buff; /* The buffer of information from the * client. */ char *pservname; /* The service name to be supported.*/ int option; int priority; int name_id; void *name_struct; int xport = COMM_PSX_XPORT; // transport mechanism int handle = COMM_WILD_HANDLE; // for COMM_QNX_XPORT, receive all /* Set to invalid values to facilitate error exits. */ pdb = NULL; psvc_clt = NULL; pusr = NULL; name_id = ERROR; name_struct = NULL; verbose_flag = FALSE; pservname = DEFAULT_SERVICE; while( (option = getopt( argc, argv, "S:P:qQv?" )) != EOF ) { switch( option ) { case 'v': verbose_flag = TRUE; break; case 'P': priority = atoi( optarg ); if( setprio( 0, priority ) == ERROR ) { fprintf(stderr, "Can't change priority to %d\n", priority ); exit( EXIT_FAILURE ); } break; case 'S': pservname = optarg; break; case 'q': xport = COMM_QNX_XPORT; break; case 'Q': xport = COMM_QNX6_XPORT; break; case '?': default: usage( argv[0] ); exit( EXIT_FAILURE ); break; } } if (verbose_flag) { printf("Starting PATH DB data server\n"); fflush(stdout); } if ( !slv_db_publish_name (xport, pservname, &name_id, &name_struct) ) { fprintf( stderr, "Can't publish service %s\n", pservname); slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct); exit( EXIT_FAILURE ); } /* Beware that name_id is now the channel id in QNX 6, so * don't want to pass in COMM_WILD_HANDLE. But code for QNX 4 * assumes COMM_WILD_HANDLE, so must special case this */ if ( COMM_QNX6_XPORT == xport ) { handle = comm_get_handle( xport, pservname, name_id ); } else { handle = comm_get_handle( xport, pservname, COMM_WILD_HANDLE ); } if( (pdb = slv_db_create()) == NULL ) { fprintf( stderr, "%s: Can't create database\n", argv[0] ); slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct ); exit( EXIT_FAILURE ); } else if( (psvc_clt = comm_init( xport, handle )) == NULL ) { fprintf( stderr, "%s: Can't create server communications\n", argv[0] ); slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct ); exit( EXIT_FAILURE ); } else if( (pusr = dl_create()) == NULL ) { fprintf( stderr, "%s: Can't create usr list\n", argv[0] ); slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct ); exit( EXIT_FAILURE ); } else if( setjmp( exit_env ) != 0 ) { slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct ); exit( EXIT_SUCCESS ); } else sig_ign( sig_list, sig_hand ); if (verbose_flag) { printf("db slv: pdb 0x%x pusr 0x%x\n", (unsigned int) pdb, (unsigned int) pusr); } while( (pdb_clt = comm_sync_recv( psvc_clt, &recv_buff, DB_COMM_SIZE )) != NULL ) { if( verbose_flag == TRUE ) db_print( &recv_buff ); if( (slv_cmd( pdb, pusr, pdb_clt, &recv_buff ) == FALSE) && (verbose_flag == TRUE) ) { printf( "%s: processing failed.\n", argv[0] ); db_print( &recv_buff ); } } longjmp( exit_env, EXIT_FAILURE ); }
/**************************************************************************** * Exported Functions ****************************************************************************/ uint8 dlt_test_1(void) { DL_LIST *list_1 = NULL; DL_LIST *list_2 = NULL; DL_LIST *list_3 = NULL; DL_LIST *list_4 = NULL; DL_LIST *node_1; DL_LIST *node_2; DL_LIST *node_3; DL_LIST *node_4; DL_LIST *node_5; DLT_OBJECT *object_0; DLT_OBJECT *object_1; DLT_OBJECT *object_2; DLT_OBJECT *object_3; DLT_OBJECT *object_4; DLT_OBJECT *object_5; DLT_OBJECT *object_6; DLT_OBJECT *object_7; DLT_OBJECT *object_8; DLT_OBJECT *object_9; uint8 result = DLT_SUCCESS; uint16 tag_0; UART_1_Start(); UART_1_PutString("\x1b\x5b\x32\x4a"); UART_1_PutString("DOUBLY LINKED LIST LIBRARY TEST\r\n"); UART_1_PutString("\r\n"); UART_1_PutString("Test\tFunction\t\tResult\r\n"); UART_1_PutString("----\t--------\t\t------\r\n"); /* * Initialise dl_create() test. */ if (result == DLT_SUCCESS) { if (_create_object("one", 1, &object_1) == DLT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_create(). */ if (result == DLT_SUCCESS) { if (dl_create(NULL, _TAG, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 1\tdl_create()\t\tPASS\r\n"); } else { UART_1_PutString(" 1\tdl_create()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_create(NULL, _TAG, object_1) == DL_BAD_ARGUMENT) { UART_1_PutString(" 2\tdl_create()\t\tPASS\r\n"); } else { UART_1_PutString(" 2\tdl_create()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_create(&node_1, _TAG, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 3\tdl_create()\t\tPASS\r\n"); } else { UART_1_PutString(" 3\tdl_create()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_create(&node_1, _TAG, object_1) == DL_SUCCESS) { UART_1_PutString(" 4\tdl_create()\t\tPASS\r\n"); } else { UART_1_PutString(" 4\tdl_create()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Initialise dl_insert_before() test. */ if (result == DLT_SUCCESS) { if (_create_object("two", 2, &object_2) == DLT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (_create_object("three", 3, &object_3) == DLT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_create(&node_2, _TAG, object_2) == DL_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_create(&node_3, _TAG, object_3) == DL_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_insert_before(). */ if (result == DLT_SUCCESS) { if (dl_insert_before(NULL, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 5\tdl_insert_before()\tPASS\r\n"); } else { UART_1_PutString(" 5\tdl_insert_before()\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_insert_before(NULL, node_1) == DL_BAD_ARGUMENT) { UART_1_PutString(" 6\tdl_insert_before()\tPASS\r\n"); } else { UART_1_PutString(" 6\tdl_insert_before()\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_insert_before(node_3, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 7\tdl_insert_before()\tPASS\r\n"); } else { UART_1_PutString(" 7\tdl_insert_before()\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_insert_before(node_3, node_1) == DL_SUCCESS) { UART_1_PutString(" 8\tdl_insert_before()\tPASS\r\n"); } else { UART_1_PutString(" 8\tdl_insert_before()\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_insert_before(node_3, node_2) == DL_SUCCESS) { UART_1_PutString(" 9\tdl_insert_before()\tPASS\r\n"); } else { UART_1_PutString(" 9\tdl_insert_before()\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Initialise dl_insert_after() test. */ if (result == DLT_SUCCESS) { if (_create_object("four", 4, &object_4) == DLT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (_create_object("five", 5, &object_5) == DLT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_create(&node_4, _TAG, object_4) == DL_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_create(&node_5, _TAG, object_5) == DL_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_insert_after(). */ if (result == DLT_SUCCESS) { if (dl_insert_after(NULL, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 10\tdl_insert_after()\tPASS\r\n"); } else { UART_1_PutString(" 10\tdl_insert_after()\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_insert_after(NULL, node_5) == DL_BAD_ARGUMENT) { UART_1_PutString(" 11\tdl_insert_after()\tPASS\r\n"); } else { UART_1_PutString(" 11\tdl_insert_after()\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_insert_after(node_3, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 12\tdl_insert_after()\tPASS\r\n"); } else { UART_1_PutString(" 12\tdl_insert_after()\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_insert_after(node_3, node_5) == DL_SUCCESS) { UART_1_PutString(" 13\tdl_insert_after()\tPASS\r\n"); } else { UART_1_PutString(" 13\tdl_insert_after()\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_insert_after(node_3, node_4) == DL_SUCCESS) { UART_1_PutString(" 14\tdl_insert_after()\tPASS\r\n"); } else { UART_1_PutString(" 14\tdl_insert_after()\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_get_first(). */ if (result == DLT_SUCCESS) { if (dl_get_first(NULL) == NULL) { UART_1_PutString(" 15\tdl_get_first()\t\tPASS\r\n"); } else { UART_1_PutString(" 15\tdl_get_first()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_get_first(node_3) == node_1) { UART_1_PutString(" 16\tdl_get_first()\t\tPASS\r\n"); } else { UART_1_PutString(" 16\tdl_get_first()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Initialise dl_add_first() test. */ if (result == DLT_SUCCESS) { if (_create_object("six", 6, &object_6) == DLT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (_create_object("seven", 7, &object_7) == DLT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_add_first(). */ if (result == DLT_SUCCESS) { if (dl_add_first(NULL, _TAG, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 17\tdl_add_first()\t\tPASS\r\n"); } else { UART_1_PutString(" 17\tdl_add_first()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_first(NULL, _TAG, object_7) == DL_BAD_ARGUMENT) { UART_1_PutString(" 18\tdl_add_first()\t\tPASS\r\n"); } else { UART_1_PutString(" 18\tdl_add_first()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_first(&list_1, _TAG, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 19\tdl_add_first()\t\tPASS\r\n"); } else { UART_1_PutString(" 19\tdl_add_first()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_first(&list_1, _TAG, object_7) == DL_SUCCESS) { UART_1_PutString(" 20\tdl_add_first()\t\tPASS\r\n"); } else { UART_1_PutString(" 20\tdl_add_first()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_first(&list_1, _TAG, object_6) == DL_SUCCESS) { UART_1_PutString(" 21\tdl_add_first()\t\tPASS\r\n"); } else { UART_1_PutString(" 21\tdl_add_first()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_get_last(). */ if (result == DLT_SUCCESS) { if (dl_get_last(NULL) == NULL) { UART_1_PutString(" 22\tdl_get_last()\t\tPASS\r\n"); } else { UART_1_PutString(" 22\tdl_get_last()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_get_last(node_3) == node_5) { UART_1_PutString(" 23\tdl_get_last()\t\tPASS\r\n"); } else { UART_1_PutString(" 23\tdl_get_last()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Initialise dl_add_last() test. */ if (result == DLT_SUCCESS) { if (_create_object("eight", 8, &object_8) == DLT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (_create_object("nine", 9, &object_9) == DLT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_add_last(). */ if (result == DLT_SUCCESS) { if (dl_add_last(NULL, _TAG, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 24\tdl_add_last()\t\tPASS\r\n"); } else { UART_1_PutString(" 24\tdl_add_last()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_last(NULL, _TAG, object_8) == DL_BAD_ARGUMENT) { UART_1_PutString(" 25\tdl_add_last()\t\tPASS\r\n"); } else { UART_1_PutString(" 25\tdl_add_last()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_last(&list_2, _TAG, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 26\tdl_add_last()\t\tPASS\r\n"); } else { UART_1_PutString(" 26\tdl_add_last()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_last(&list_2, _TAG, object_8) == DL_SUCCESS) { UART_1_PutString(" 27\tdl_add_last()\t\tPASS\r\n"); } else { UART_1_PutString(" 27\tdl_add_last()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_last(&list_2, _TAG, object_9) == DL_SUCCESS) { UART_1_PutString(" 28\tdl_add_last()\t\tPASS\r\n"); } else { UART_1_PutString(" 28\tdl_add_last()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_get_previous(). */ if (result == DLT_SUCCESS) { if (dl_get_previous(NULL) == NULL) { UART_1_PutString(" 29\tdl_get_previous()\tPASS\r\n"); } else { UART_1_PutString(" 29\tdl_get_previous()\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_get_previous(node_3) == node_2) { UART_1_PutString(" 30\tdl_get_previous()\tPASS\r\n"); } else { UART_1_PutString(" 30\tdl_get_previous()\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_add_before(). */ if (result == DLT_SUCCESS) { if (dl_add_before(NULL, _TAG, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 31\tdl_add_before()\t\tPASS\r\n"); } else { UART_1_PutString(" 31\tdl_add_before()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_before(NULL, _TAG, object_2) == DL_BAD_ARGUMENT) { UART_1_PutString(" 32\tdl_add_before()\t\tPASS\r\n"); } else { UART_1_PutString(" 32\tdl_add_before()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_before(&list_3, _TAG, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 33\tdl_add_before()\t\tPASS\r\n"); } else { UART_1_PutString(" 33\tdl_add_before()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_before(&list_3, _TAG, object_2) == DL_SUCCESS) { UART_1_PutString(" 34\tdl_add_before()\t\tPASS\r\n"); } else { UART_1_PutString(" 34\tdl_add_before()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_before(&list_3, _TAG, object_1) == DL_SUCCESS) { UART_1_PutString(" 35\tdl_add_before()\t\tPASS\r\n"); } else { UART_1_PutString(" 35\tdl_add_before()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_get_next(). */ if (result == DLT_SUCCESS) { if (dl_get_next(NULL) == NULL) { UART_1_PutString(" 36\tdl_get_next()\t\tPASS\r\n"); } else { UART_1_PutString(" 36\tdl_get_next()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_get_next(node_3) == node_4) { UART_1_PutString(" 37\tdl_get_next()\t\tPASS\r\n"); } else { UART_1_PutString(" 37\tdl_get_next()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_add_after(). */ if (result == DLT_SUCCESS) { if (dl_add_after(NULL, _TAG, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 38\tdl_add_after()\t\tPASS\r\n"); } else { UART_1_PutString(" 38\tdl_add_after()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_after(NULL, _TAG, object_3) == DL_BAD_ARGUMENT) { UART_1_PutString(" 39\tdl_add_after()\t\tPASS\r\n"); } else { UART_1_PutString(" 39\tdl_add_after()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_after(&list_4, _TAG, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 40\tdl_add_after()\t\tPASS\r\n"); } else { UART_1_PutString(" 40\tdl_add_after()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_after(&list_4, _TAG, object_3) == DL_SUCCESS) { UART_1_PutString(" 41\tdl_add_after()\t\tPASS\r\n"); } else { UART_1_PutString(" 41\tdl_add_after()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_after(&list_4, _TAG, object_4) == DL_SUCCESS) { UART_1_PutString(" 42\tdl_add_after()\t\tPASS\r\n"); } else { UART_1_PutString(" 42\tdl_add_after()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_get_count(). */ if (result == DLT_SUCCESS) { if (dl_get_count(NULL) == 0) { UART_1_PutString(" 43\tdl_get_count()\t\tPASS\r\n"); } else { UART_1_PutString(" 43\tdl_get_count()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_get_count(node_3) == 5) { UART_1_PutString(" 44\tdl_get_count()\t\tPASS\r\n"); } else { UART_1_PutString(" 44\tdl_get_count()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_get_object(). */ if (result == DLT_SUCCESS) { if (dl_get_object(NULL, NULL, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 45\tdl_get_object()\t\tPASS\r\n"); } else { UART_1_PutString(" 45\tdl_get_object()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_get_object(NULL, NULL, (void **)&object_0) == DL_BAD_ARGUMENT) { UART_1_PutString(" 46\tdl_get_object()\t\tPASS\r\n"); } else { UART_1_PutString(" 46\tdl_get_object()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_get_object(node_3, NULL, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 47\tdl_get_object()\t\tPASS\r\n"); } else { UART_1_PutString(" 47\tdl_get_object()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_get_object(node_3, NULL, (void **)&object_0) == DL_SUCCESS) { UART_1_PutString(" 48\tdl_get_object()\t\tPASS\r\n"); } else { UART_1_PutString(" 48\tdl_get_object()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (object_0->number == 3) { UART_1_PutString(" 49\tdl_get_object()\t\tPASS\r\n"); } else { UART_1_PutString(" 49\tdl_get_object()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_get_object(node_3, &tag_0, (void **)&object_0) == DL_SUCCESS) { UART_1_PutString(" 50\tdl_get_object()\t\tPASS\r\n"); } else { UART_1_PutString(" 50\tdl_get_object()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (tag_0 == 200) { UART_1_PutString(" 51\tdl_get_object()\t\tPASS\r\n"); } else { UART_1_PutString(" 51\tdl_get_object()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_extract(). */ if (result == DLT_SUCCESS) { if (dl_extract(NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 52\tdl_extract()\t\tPASS\r\n"); } else { UART_1_PutString(" 52\tdl_extract()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_extract(node_4) == DL_SUCCESS) { UART_1_PutString(" 53\tdl_extract()\t\tPASS\r\n"); } else { UART_1_PutString(" 53\tdl_extract()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_delete(). */ if (result == DLT_SUCCESS) { if (dl_delete(NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 54\tdl_delete()\t\tPASS\r\n"); } else { UART_1_PutString(" 54\tdl_delete()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_delete(node_5) == DL_SUCCESS) { UART_1_PutString(" 55\tdl_delete()\t\tPASS\r\n"); node_5 = NULL; } else { UART_1_PutString(" 55\tdl_delete()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_destroy(). */ if (result == DLT_SUCCESS) { if (dl_destroy(NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 56\tdl_destroy()\t\tPASS\r\n"); } else { UART_1_PutString(" 56\tdl_destroy()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_destroy(&node_2) == DL_SUCCESS) { UART_1_PutString(" 57\tdl_destroy()\t\tPASS\r\n"); } else { UART_1_PutString(" 57\tdl_destroy()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (node_2 == NULL) { UART_1_PutString(" 58\tdl_destroy()\t\tPASS\r\n"); } else { UART_1_PutString(" 58\tdl_destroy()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_join(). */ if (result == DLT_SUCCESS) { if (dl_join(NULL, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 59\tdl_join()\t\tPASS\r\n"); } else { UART_1_PutString(" 59\tdl_join()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_join(NULL, list_2) == DL_BAD_ARGUMENT) { UART_1_PutString(" 60\tdl_join()\t\tPASS\r\n"); } else { UART_1_PutString(" 60\tdl_join()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_join(list_1, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 61\tdl_join()\t\tPASS\r\n"); } else { UART_1_PutString(" 61\tdl_join()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_join(list_1, list_2) == DL_SUCCESS) { UART_1_PutString(" 62\tdl_join()\t\tPASS\r\n"); } else { UART_1_PutString(" 62\tdl_join()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Initialise dl_exchange() test. */ if (result == DLT_SUCCESS) { if (dl_join(list_3, list_4) == DL_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_add_last(&list_4, _TAG, object_5) == DL_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_join(list_4, list_1) == DL_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { node_1 = dl_get_first(list_1); node_2 = list_3; node_3 = list_4; } /* * Test dl_exchange(). */ if (result == DLT_SUCCESS) { if (dl_exchange(NULL, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 63\tdl_exchange()\t\tPASS\r\n"); } else { UART_1_PutString(" 63\tdl_exchange()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_exchange(NULL, node_2) == DL_BAD_ARGUMENT) { UART_1_PutString(" 64\tdl_exchange()\t\tPASS\r\n"); } else { UART_1_PutString(" 64\tdl_exchange()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_exchange(node_1, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 65\tdl_exchange()\t\tPASS\r\n"); } else { UART_1_PutString(" 65\tdl_exchange()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_exchange(node_1, node_2) == DL_SUCCESS) { UART_1_PutString(" 66\tdl_exchange()\t\tPASS\r\n"); } else { UART_1_PutString(" 66\tdl_exchange()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_exchange(node_1, node_2) == DL_SUCCESS) { UART_1_PutString(" 67\tdl_exchange()\t\tPASS\r\n"); } else { UART_1_PutString(" 67\tdl_exchange()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_exchange(node_1, node_3) == DL_SUCCESS) { UART_1_PutString(" 68\tdl_exchange()\t\tPASS\r\n"); } else { UART_1_PutString(" 68\tdl_exchange()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_exchange(node_1, node_3) == DL_SUCCESS) { UART_1_PutString(" 69\tdl_exchange()\t\tPASS\r\n"); } else { UART_1_PutString(" 69\tdl_exchange()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Test dl_update(). */ if (result == DLT_SUCCESS) { if (dl_update(NULL, _TAG, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 70\tdl_update()\t\tPASS\r\n"); } else { UART_1_PutString(" 70\tdl_update()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_update(NULL, _TAG, object_1) == DL_BAD_ARGUMENT) { UART_1_PutString(" 71\tdl_update()\t\tPASS\r\n"); } else { UART_1_PutString(" 71\tdl_update()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_update(&node_5, _TAG, NULL) == DL_BAD_ARGUMENT) { UART_1_PutString(" 72\tdl_update()\t\tPASS\r\n"); } else { UART_1_PutString(" 72\tdl_update()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { if (dl_update(&node_5, _TAG, object_1) == DL_SUCCESS) { UART_1_PutString(" 73\tdl_update()\t\tPASS\r\n"); } else { UART_1_PutString(" 73\tdl_update()\t\tFAIL\r\n"); result = DLT_FAILURE; } } if (result == DLT_SUCCESS) { object_0 = node_5->object; if (object_0->number == 1) { UART_1_PutString(" 74\tdl_update()\t\tPASS\r\n"); } else { UART_1_PutString(" 74\tdl_update()\t\tFAIL\r\n"); result = DLT_FAILURE; } } /* * Report test result. */ if (result == DLT_SUCCESS) { UART_1_PutString("\r\n"); UART_1_PutString("TEST PASSED\r\n"); } else { UART_1_PutString("\r\n"); UART_1_PutString("TEST FAILED\r\n"); } /* * Clean-up test. */ _destroy_object(object_1); _destroy_object(object_2); _destroy_object(object_3); _destroy_object(object_4); _destroy_object(object_5); _destroy_object(object_6); _destroy_object(object_7); _destroy_object(object_8); _destroy_object(object_9); dl_delete(node_4); dl_destroy(&list_1); while ((UART_1_ReadTxStatus() & UART_1_TX_STS_FIFO_EMPTY) != UART_1_TX_STS_FIFO_EMPTY) { CyDelay(1); } UART_1_Stop(); return result; }