void test_expr_to_tab() { char** tab; tab = expr_to_tab(" 56 * ((6+2) / ( 8-7)* 2%3)", "0123456789", "()+-*/%"); test_str(tab[0], "56"); test_str(tab[1], "*"); test_str(tab[2], "("); test_str(tab[3], "("); test_str(tab[4], "6"); test_str(tab[8], "/"); test_str(tab[16], "%"); test(tab[19] == 0); free_tab(tab); tab = expr_to_tab("0101|[1001$10101]", "01", "[]+-*|$"); test_str(tab[0], "0101"); free_tab(tab); //wrong operator tab = expr_to_tab(" 56 * ((6+2) / ( 8-7)* 2^3)", "0123456789", "()+-*/%"); test(tab == 0); //wrong operande tab = expr_to_tab(" 56 * ((6+2) / ( E-7)* 2^3)", "0123456789", "()+-*/%"); test(tab == 0); //Wrong syntax tab = expr_to_tab(" 56 * * ((6+2) / ( E-7)* 2^3)", "0123456789", "()+-*/%"); test(tab == 0); //good syntax tab = expr_to_tab(" 56 * ((6++-2) / ( 8-7)* 2%3)", "0123456789", "()+-*/%"); test(tab != 0); test_str(tab[5], "-"); free_tab(tab); }
char *ft_convert_base(char *nbr, char *base_from, char *base_to) { int nb; int i; int sg; nb = 0; i = 0; sg = 1; if (ft_strlen(base_from) <= 1 || test_str(nbr, base_from) == 1) return (0); while ((nbr[i] == ' ') || (nbr[i] == ' ')) i++; if ((nbr[i] == '-') || (nbr[i] == '+')) { if (nbr[i] == '-') sg *= -1; i++; } while (nbr[i] != '\0') { if (stri_is_good(nbr[i], base_from, 1)) return (itoa_chelou(nb * sg, base_to)); nb = nb * ft_strlen(base_from) + (stri_is_good(nbr[i], base_from, 0)); i++; } return (itoa_chelou(nb * sg, base_to)); }
void apply() { std::string test_str("Testing"); boost::asio::io_service ios; using lock_t = std::unique_lock<std::mutex>; lock_t::mutex_type mtx; std::condition_variable cv; bool finished = false; { auto s = aziomq::thread::fork(ios, [&](aziomq::socket p, std::string msg) { p.send(boost::asio::buffer(msg)); auto& ios = p.get_io_service(); ios.run(); { lock_t lk(mtx); finished = true; } cv.notify_one(); }, test_str); std::array<char, 1025> buf; auto bytes_transferred = s.receive(boost::asio::buffer(buf)); auto res = detail::check_res(std::string(buf.data(), bytes_transferred), test_str); if (res != std::exception_ptr()) std::rethrow_exception(res); } { lock_t lk(mtx); cv.wait(lk, [&] { return finished; }); } }
static int test_filter(struct event_format *event, struct filter_arg *arg, struct pevent_record *record) { switch (arg->type) { case FILTER_ARG_BOOLEAN: /* easy case */ return arg->boolean.value; case FILTER_ARG_OP: return test_op(event, arg, record); case FILTER_ARG_NUM: return test_num(event, arg, record); case FILTER_ARG_STR: return test_str(event, arg, record); case FILTER_ARG_EXP: case FILTER_ARG_VALUE: case FILTER_ARG_FIELD: /* * Expressions, fields and values evaluate * to true if they return non zero */ return !!get_arg_value(event, arg, record); default: die("oops!"); /* ?? */ return 0; } }
int main(int argc, char **argv) { test_str(); test_vec(); test_matrix(); test_stats(); test_list(); }
msg_ptr_t make_test_str(size_t test_str_size) { std::ostringstream ostr; ostr << iclock64(); std::string msg_str = ostr.str(); msg_str += test_str(CLOCK_INTERVAL_STR, test_str_size - msg_str.size()); return msg_ptr_t(new std::string(msg_str)); }
std::string make_test_str(size_t test_str_size) { std::ostringstream ostr; ostr << CLOCK_START_STR << iclock64(); std::string msg_str = ostr.str(); msg_str += test_str(CLOCK_INTERVAL_STR, test_str_size - msg_str.size()); return msg_str; }
int main(void) { test_gprmc2(&pq_obj); test_gpgga(&pq_obj); test_sentence(&pq_obj); test_gprmc(&pq_obj); test_str(&pq_obj); test_float(&pq_obj); }
/*===========================================================================* * sef_cb_init_fresh * *===========================================================================*/ static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info)) { /* Run all the tests. */ test_u32(); test_str(); test_mem(); test_map(); test_label(); return OK; }
void print_over_test_str_nl_( #if defined(OS_WINDOWS) unsigned long level, #else long level, #endif char *str) { unsigned long len; if(level < 0) level = 0; if(level > strlen(_empt_str)/4) level = strlen(_empt_str)/4; len = strlen(str); if(len <= strlen(test_str(level)) - 4) printf("%s%s%s\n", empty_str(level), str, &(test_str(level)[len])); else printf("%s%s... \n", empty_str(level), str); }
void test_proc(void) { test_str(""); test_str(" "); test_str("\t"); test_str("\r\n"); test_str("Hello world!!!"); test_str(" Hello world!!! (space) \n"); test_str("\tHello\tworld!!!\t(tab)\t\r\n"); }
void test_lazy_string_utils_find() { std::string ref_str("1234567890"); lazy::lazy_string test_str("1234567890"); test("find function finds existing substr with zero offset", ref_str.find("67") == find(test_str, "67") && find(test_str, "67") == 5); test("find function finds existing substr with non-zero offset", ref_str.find("67", 5) == find(test_str, "67", 5) && find(test_str, "67", 5) == 5); test("find function doesn't find not existing substr", find(test_str, "foo") == lazy::lazy_string::npos); }
/*===========================================================================* * main * *===========================================================================*/ int main(void) { /* SEF local startup. */ sef_local_startup(); /* Run all the tests. */ test_u32(); test_str(); test_mem(); test_map(); test_label(); return 0; }
int test_mem() { char ss10[10] = { 0,1,2,3,4,5,6,7,8,9 }; char ss0[10] = { 0 }; char *d; FFTEST_FUNC; d = ffmem_alloc(10); x(d != NULL); memcpy(d, ss10, 10); d = ffmem_realloc(d, 2000); x(d != NULL); x(!memcmp(d, ss10, 10)); ffmem_free(d); d = ffmem_calloc(1, 10); x(d != NULL); x(!memcmp(d, ss0, 10)); ffmem_free(d); d = ffmem_realloc(NULL, 10); x(d != NULL); ffmem_free(d); #if defined FF_WIN x(NULL == ffmem_alloc(FFINT_SMAX)); x(NULL == ffmem_calloc(FFINT_SMAX, 1)); x(NULL == ffmem_realloc(NULL, FFINT_SMAX)); #endif //align x(NULL != (d = ffmem_align(4, 16))); x(((size_t)d % 16) == 0); ffmem_alignfree(d); x(NULL != (d = ffmem_align(999, 512))); x(((size_t)d % 512) == 0); ffmem_alignfree(d); test_str(); return 0; }
void test_expr_to_npi() { char** tab; tab = expr_to_tab("56 * ((6+2) / ( 8-7)* 2%3)", "0123456789", "()+-*/%"); tab = expr_to_npi(tab, "0123456789", "()+-*/%"); test_str(tab[0], "56"); test_str(tab[1], "6"); test_str(tab[2], "2"); test_str(tab[3], "+"); test_str(tab[4], "8"); test_str(tab[5], "7"); free_tab(tab); }
int main() { begin_test_data(expected_t) test_data( "nothing to skip!", 0, test_pair(1,1), PDS_OK ), test_data( "\t \r\n end", 8, test_pair(1,2), PDS_OK ), test_data( "/**/ end", 5, test_pair(1,1), PDS_OK ), test_data( "/* a\tlonger\tcomment */\t\r\n\r\nend", 27, test_pair(1,3), PDS_OK ), test_data(" \t/*line 1 */\n \t\t/*line 2*/\n \t\t\t/*line 3*/\nend", 44, test_pair(1,4), PDS_OK ), test_data( " /* /* nested comment */", 5, test_pair(0,1), PDS_INVALID_VALUE ), test_data( " /* muti-line \n comment */", 15, test_pair(0,1), PDS_INVALID_VALUE ), end_test_data() PDS_parser parser; memset(&parser, 0, sizeof(PDS_parser)); PDS_set_error_callback(&parser.callbacks, dummy_error); size_t i; test_foreach(i) { parser.line_num = 1; parser.first = test_str(i); parser.current = parser.first; parser.last = parser.first + strlen(parser.first) - 1; parser.status = PDS_OK; int ret; ret = PDS_skip_whitespaces(&parser); check(test_status(i) == parser.status); check(test_end(i) == parser.current); check(test_expected(i).ret == ret); check(test_expected(i).line == parser.line_num); } return EXIT_SUCCESS; }
int main(int argc, char **argv) { if (argc > 1) { if (!strcmp(argv[1], "v")) { Verbose = 1; } else if (!strcmp(argv[1], "test-stdout")) { test_stdout(); return EXIT_SUCCESS; } if (!strcmp(argv[1], "test-atexit")) { test_atexit(); return EXIT_SUCCESS; } } test_mem(); test_str(); test_sprintf(); test_math(); test_proc(); test_stdio(); test_file(); test_exit(); return EXIT_FAILURE; }
int main (void) { printf("\nWorking\n"); test_str("asdfghjk", "f"); printf("\nEnd\n"); test_str("asdf<<value == \"hi!\">>qqqq", "qqq"); printf("\nStrings Identical\n"); test_str("<<hi>>", "<<hi>>"); printf("\nStart not in Source\n"); test_str("<<hi>>", "asdf"); printf("\nSmall Source\n"); test_str("s", "sdf"); printf("\nTwice\n"); test_str("QQ<<JJ<<FF<<JJ", "JJ"); printf("\nNull Termination Only\n"); test_str("mbk", ""); }
ATF_TC_BODY(id_colon_ascii, tc) { test_str(test_eui64_id_colon_ascii, &test_eui64_id); }
/** * Test a hash algorithm on array of known short messages. * * @param hash_id id of the algorithm to test * @param ptr pointer to array of pairs <message,expected-hash> */ static void test_known_strings2(unsigned hash_id, const char** ptr) { for(; ptr[0] && ptr[1]; ptr += 2) { test_str(ptr[0], ptr[1], hash_id); } }
test_data("failure = {{1,2,3,4,5,6}}\r\n", 0, &set[1], PDS_INVALID_VALUE), end_test_data() PDS_parser parser; memset(&parser, 0, sizeof(PDS_parser)); PDS_set_error_callback(&parser.callbacks, dummy_error); PDS_set_set_callbacks(&parser.callbacks, set_begin_callback, set_end_callback); PDS_set_scalar_callback(&parser.callbacks, set_element_callback); size_t i; test_foreach(i) { state_t state = { .index = 0, .expected = test_expected(i) }; parser.line_num = 1; parser.first = test_str(i); parser.last = parser.first + strlen(parser.first) - 1; parser.current = parser.first; parser.status = PDS_OK; parser.user_data = &state; int ret = PDS_parse_statement(&parser); check(test_status(i) == parser.status); if(ret) { check(test_end(i) == parser.current); } } return EXIT_SUCCESS; }
void CharacterImageObject::update_text() { lines.clear(); blocks.clear(); total_height[0] = total_height[1] = total_height[2] = 0; if (text.empty()) return; char * data = &text[0]; char * end = data + text.size(); char * start_text = NULL; char * tag_start = NULL; AttributeStack alias_stack(ALIAS_ATTRIB); AttributeStack tracking_stack(TRACKING_ATTRIB); AttributeStack transparent_stack(TRANSPARENT_ATTRIB); lines.resize(1); CharacterImageAttributes attribs; int line = 0; int line_height = 0; int line_width = 0; int leading = 0; while (true) { // read text char * text_start = data; char * wrap_point = data; int test_width = line_width; bool wrap_newline = false; bool has_newline = false; // scan for newline, tag start or wrap point while (true) { if (data >= end) break; unsigned char c = (unsigned char)*data; if (c == '\n') { data++; has_newline = true; break; } else if (c == '\r') { data++; continue; } else if (c == '[') break; if (c == ' ') wrap_point = data+1; int alias_index = attribs.values[ALIAS_ATTRIB]; CharacterImageAlias & alias = aliases[alias_index]; CharacterImage & img = alias.charmap[c]; test_width += img.width + attribs.values[TRACKING_ATTRIB]; if (c != ' ' && (test_width+1) >= width) { data = wrap_point; has_newline = true; wrap_newline = true; break; } data++; } char * text_end = data; bool at_end = data >= end; if (text_start != text_end) { int alias_index = attribs.values[ALIAS_ATTRIB]; CharacterImageAlias & alias = aliases[alias_index]; std::string new_text(text_start, text_end - text_start); for (int i = 0; i < int(new_text.size()); i++) { unsigned char c = (unsigned char)new_text[i]; CharacterImage & img = alias.charmap[c]; line_height = std::max(img.height, line_height); if (c == '\n' || c == '\r') continue; line_width += img.width + attribs.values[TRACKING_ATTRIB]; } if (line_height == 0) line_height = alias.charmap[' '].height; unformatted += new_text; blocks.push_back(CharacterImageBlock(line, attribs, new_text)); } if (has_newline || at_end) { CharacterImageLine & l = lines[line]; l.width = line_width; line_height += (line_height * leading) / 100; total_height[get_vertical_index(l)] += line_height; l.height = line_height; line_width = line_height = 0; if (!wrap_newline) leading = 0; line++; } if (at_end) return; if (has_newline) { lines.resize(line+1); if (wrap_newline) { // inherit line config lines[line].x_align = lines[line-1].x_align; lines[line].y_align = lines[line-1].y_align; } } if (has_newline) continue; // read tag data++; // skip '['' data = lskip(data, end); bool is_end_tag = *data == '/'; if (is_end_tag) { data++; data = lskip(data, end); } char * tag_start = data; data = find_tag_end(data, end); char * tag_end = data; // read tag value data = lskip(data, end); bool has_value = *data == '='; char * value_start; char * value_end; if (*data == '=') { data++; data = lskip(data, end); value_start = data; data = find_tag_end(data, end); value_end = data; } data = find_char(data, end, ']'); data++; // convert value to integer int value; if (has_value) { bool is_alignment = true; switch (value_start[0]) { case 'l': // left value = ALIGN_LEFT; break; case 'r': // right value = ALIGN_RIGHT; break; case 'c': // centre value = ALIGN_HCENTER | ALIGN_VCENTER; break; case 'j': // justify value = ALIGN_JUSTIFY; break; case 't': // top value = ALIGN_TOP; break; case 'b': // bottom value = ALIGN_BOTTOM; break; default: is_alignment = false; break; } if (!is_alignment) { std::string value_str(value_start, value_end-value_start); value = string_to_int(value_str); } } // test attributes AttributeStack * stack_ref; if (test_str(tag_start, tag_end, "alias")) { stack_ref = &alias_stack; } else if (test_str(tag_start, tag_end, "tracking")) { stack_ref = &tracking_stack; } else if (test_str(tag_start, tag_end, "transparent")) { stack_ref = &transparent_stack; } else if (test_str(tag_start, tag_end, "veralign")) { lines[line].y_align = value; continue; } else if (test_str(tag_start, tag_end, "horalign")) { lines[line].x_align = value; continue; } else if (test_str(tag_start, tag_end, "leading")) { leading = value; continue; } else { std::string tag(tag_start, tag_end - tag_start); std::cout << "Unknown tag: " << tag << std::endl; continue; } if (is_end_tag) { stack_ref->pop(attribs); continue; } stack_ref->push(value, attribs); } }
ATF_TC_BODY(hex_ascii, tc) { test_str(test_eui64_hex_ascii, &test_eui64_id); }
static int test_strs(void) { plan(96); header(); test_str(0x01); test_str(0x1e); test_str(0x1f); test_str(0x20); test_str(0xfe); test_str(0xff); test_str(0x100); test_str(0x101); test_str(0xfffe); test_str(0xffff); test_str(0x10000); test_str(0x10001); footer(); return check_plan(); }
std::size_t TemplightProtobufWriter::createDictionaryEntry(const std::string &NameOrig) { std::unordered_map<std::string, std::size_t>::iterator it_found = templateNameMap.find(NameOrig); if (it_found != templateNameMap.end()) return it_found->second; // FIXME: Convert this code to being constructive of "Name", instead of // destructive (replacing sub-strings with '\0' characters). std::string Name = NameOrig; std::string::iterator it_open = Name.end(); std::string::iterator it_colon_lo = Name.begin(); int srch_state = 0; llvm::SmallVector<std::size_t, 8> markers; for (std::string::iterator it = Name.begin(); it != Name.end(); ++it) { switch (srch_state) { case 0: if (*it == '<') { // check for "operator<<", "operator<" and "operator<=" llvm::StringRef test_str(Name.data(), it - Name.begin() + 1); if (test_str.endswith("operator<")) { it_open = Name.end(); srch_state = 0; } else { it_open = it; ++srch_state; } } else if ((*it == ':') && (it + 1 < Name.end()) && (*(it + 1) == ':')) { if (it_colon_lo < it) { markers.push_back( createDictionaryEntry(std::string(it_colon_lo, it))); std::size_t offset_lo = it_colon_lo - Name.begin(); Name.replace(it_colon_lo, it, 1, '\0'); it = Name.begin() + offset_lo + 2; } else { it += 1; } it_colon_lo = it + 1; it_open = Name.end(); } break; case 1: if (*it == '<') { // check for "operator<<" and "operator<" llvm::StringRef test_str(Name.data(), it - Name.begin() + 1); if (test_str.endswith("operator<<<")) { it_open = it; srch_state = 1; } else { ++srch_state; } } else if ((*it == ',') || (*it == '>')) { if (it_colon_lo < it_open) { std::size_t offset_end = it - it_open; std::size_t offset_lo = it_colon_lo - Name.begin(); markers.push_back( createDictionaryEntry(std::string(it_colon_lo, it_open))); Name.replace(it_colon_lo, it_open, 1, '\0'); it_open = Name.begin() + offset_lo + 1; it = it_open + offset_end; it_colon_lo = Name.end(); } std::string::iterator it_lo = it_open + 1; std::string::iterator it_hi = it - 1; trimSpaces(it_lo, it_hi); // Create or find the marker entry: markers.push_back(createDictionaryEntry(std::string(it_lo, it_hi))); std::size_t offset_end = it - it_hi; std::size_t offset_lo = it_lo - Name.begin(); Name.replace(it_lo, it_hi, 1, '\0'); it = Name.begin() + offset_lo + 1 + offset_end; it_open = it; it_colon_lo = Name.end(); if (*it == '>') { it_open = Name.end(); srch_state = 0; it_colon_lo = it + 1; } } break; default: if (*it == '<') { ++srch_state; } else if (*it == '>') { --srch_state; } break; } } if (!markers.empty() && it_colon_lo != Name.end()) { markers.push_back( createDictionaryEntry(std::string(it_colon_lo, Name.end()))); Name.replace(it_colon_lo, Name.end(), 1, '\0'); } /* message DictionaryEntry { required string marked_name = 1; repeated uint32 marker_ids = 2; } */ std::string dict_entry; llvm::raw_string_ostream OS_dict(dict_entry); llvm::protobuf::saveString(OS_dict, 1, Name); // marked_name for (llvm::SmallVector<std::size_t, 8>::iterator mk = markers.begin(), mk_end = markers.end(); mk != mk_end; ++mk) { llvm::protobuf::saveVarInt(OS_dict, 2, *mk); // marker_ids } OS_dict.str(); std::size_t id = templateNameMap.size(); templateNameMap[NameOrig] = id; llvm::raw_string_ostream OS_outer(buffer); // repeated DictionaryEntry names = 3; llvm::protobuf::saveString(OS_outer, 3, dict_entry); return id; }
ATF_TC_BODY(mac_colon_ascii, tc) { test_str(test_eui64_mac_colon_ascii, &test_eui64_eui48); }