/** * Walk down the tree from the given node following the given path * @param st the suffixtree in question * @param v the node to start from its children * @param p the path to walk down and then free * @return a position corresponding to end */ static pos *walk_down( suffixtree *st, node *v, path *p ) { pos *q=NULL; int start = path_start( p ); int len = path_len( p ); v = node_find_child( v, st->str, st->str[start] ); while ( len > 0 ) { if ( len <= node_len(v) ) { q = pos_create(); q->loc = node_start(v)+len-1; q->v = v; break; } else { start += node_len(v); len -= node_len(v); v = node_find_child( v, st->str, st->str[start] ); } } path_dispose( p ); return q; }
/** * Does the position continue with the given character? * @param st the suffixtree object * @param p a position in the tree. * @param c the character to test for in the next position * @return 1 if it does else 0 */ static int continues( suffixtree *st, pos *p, UChar c ) { if ( node_end(p->v,st->e) > p->loc ) return st->str[p->loc+1] == c; else return node_find_child(p->v,st->str,c) != NULL; }
void test_spec_handler(struct spec_handler* handler, struct spec_handler_test* tests) { GNode* node; GNode* handler_node; GNode test_node; struct cc_oci_config config; struct spec_handler_test* test; int fd; ck_assert(! handler->handle_section(NULL, NULL)); ck_assert(! handler->handle_section(&test_node, NULL)); ck_assert(! handler->handle_section(NULL, &config)); /** * Create fake files for Kernel and image so * path validation won't fail */ fd = g_creat("CONTAINER-KERNEL",0755); if (fd < 0) { g_critical ("failed to create file CONTAINER-KERNEL"); } else { close(fd); } fd = g_creat("CLEAR-CONTAINERS.img",0755); if (fd < 0) { g_critical ("failed to create file CLEAR-CONTAINERS.img"); } else { close(fd); } fd = g_creat("QEMU-LITE",0755); if (fd < 0) { g_critical ("failed to create file QEMU-LITE"); } else { close(fd); } for (test=tests; test->file; test++) { memset(&config, 0, sizeof(config)); cc_oci_json_parse(&node, test->file); handler_node = node_find_child(node, handler->name); ck_assert_msg(handler->handle_section( handler_node, &config) == test->test_result, test->file); cc_oci_config_free(&config); g_free_node(node); } if (g_remove("CONTAINER-KERNEL") < 0) { g_critical ("failed to remove file CONTAINER-KERNEL"); } if (g_remove ("CLEAR-CONTAINERS.img") < 0) { g_critical ("failed to remove file CLEAR-CONTAINERS.img"); } if (g_remove ("QEMU-LITE") < 0) { g_critical ("failed to remove file QEMU-LITE"); } }
/** * Record the position where the latest suffix was inserted * @param st the suffixtree in question * @param p the position of j..i-1. * @param i the desired index of the extra char */ static void update_old_beta( suffixtree *st, pos *p, int i ) { if ( node_end(p->v,st->e) > p->loc ) { st->old_beta.v = p->v; st->old_beta.loc = p->loc+1; } else { node *u = node_find_child( p->v, st->str, st->str[i] ); st->old_beta.v = u; st->old_beta.loc = node_start( u ); } }
/** * Advance a search by one character. * @param st the suffixtree to search * @param p the position in the tree of the last match, update if c found * @param c the character to find next * @return 1 if the next char was found else 0 */ int suffixtree_advance_pos( suffixtree *st, pos *p, UChar c ) { int res = 1; if ( node_end(p->v,st->e) > p->loc ) { if ( st->str[p->loc+1] == c ) p->loc++; else res = 0; } else { node *n = node_find_child(p->v,st->str,c); if ( n != NULL ) { p->loc = node_start(n); p->v = n; } else res = 0; } return res; }