int eval_test(char * line){ char * expr; char * bundle; char * answer; int pass = 0; if (line[0]!='#'){ //printf("%s\n", line); char delims[] = ";"; expr = strtok( line, delims ); bundle = strtok( NULL, delims ); answer = strtok( NULL, delims ); //format_newline(expr); //format_newline(bundle); //format_newline(answer); pass = test_expression(expr, bundle, answer); if (pass==0){ //printf("the expression \"%s\" and bundle \"%s\" do not produce the answer \"%s\"\n", expr, bundle, answer); } } return pass; //printf("%s,%s,%s\n", expr, bundle, answer); //test_expression("/one = /three - 2", "/three 3 \n", NULL); //printf("%d\n",test_expression(expr, bundle, answer)); //printf("%d\n",strncmp(bundle, "/three 3 \n", 10)); //format_string(bundle); //printf("%s\n", bundle); }
int main(int argc, char **argv) { frontend_init(); test_visitors(); test_semantic(); test_expression(); frontend_term(); return 0; }
int main() { std::cout << adobe::entity_unescape("Hello, world!") << std::endl; std::cout << adobe::entity_unescape(""Hello, world!'") << std::endl; std::cout << adobe::entity_escape("Hello, world!") << std::endl; std::cout << adobe::entity_escape("\"Hello, world!'") << std::endl; std::cout << "<char_rountrip_test>" << std::endl; for (long i(0); i < 256; ++i) { adobe::string_t cur; cur.push_back(static_cast<char>(i)); adobe::string_t xml(adobe::entity_escape(cur)); adobe::string_t ascii(adobe::entity_unescape(xml)); if (ascii.empty() || static_cast<unsigned char>(*ascii.begin()) != static_cast<unsigned char>(i)) throw std::runtime_error(adobe::make_string("character mismatch: ", xml.c_str())); } std::cout << "</char_rountrip_test>" << std::endl; test_expression("[ \"contains a \" '\"' \" character\" ]", &adobe::entity_escape_expression); test_expression("[ \"contains a " character\" ]", &adobe::entity_unescape_expression); test_expression("{ name: \"contains a \" '\"' \" character\" }", &adobe::entity_escape_expression); test_expression("{ name: \"contains a " character\" }", &adobe::entity_unescape_expression); }
gboolean test_rule(xmlNode * rule, GHashTable * node_hash, enum rsc_role_e role, crm_time_t * now) { xmlNode *expr = NULL; gboolean test = TRUE; gboolean empty = TRUE; gboolean passed = TRUE; gboolean do_and = TRUE; const char *value = NULL; rule = expand_idref(rule, NULL); value = crm_element_value(rule, XML_RULE_ATTR_BOOLEAN_OP); if (safe_str_eq(value, "or")) { do_and = FALSE; passed = FALSE; } crm_trace("Testing rule %s", ID(rule)); for (expr = __xml_first_child(rule); expr != NULL; expr = __xml_next_element(expr)) { test = test_expression(expr, node_hash, role, now); empty = FALSE; if (test && do_and == FALSE) { crm_trace("Expression %s/%s passed", ID(rule), ID(expr)); return TRUE; } else if (test == FALSE && do_and) { crm_trace("Expression %s/%s failed", ID(rule), ID(expr)); return FALSE; } } if (empty) { crm_err("Invalid Rule %s: rules must contain at least one expression", ID(rule)); } crm_trace("Rule %s %s", ID(rule), passed ? "passed" : "failed"); return passed; }
struct test_expression { std::size_t cost; std::string e; test_expression(const std::size_t c, const std::string& ex) : cost(c), e(ex) {} }; const test_expression global_expression_list[] = { test_expression( 1,"2 * v0" ), test_expression( 1,"v0 * 2" ), test_expression( 2,"2v0 + 3" ), test_expression( 2,"3 + 2v0" ), test_expression( 5,"(2v0 + 3) * (2v0 + 3)" ), test_expression( 5,"(3 + 2v0) * (3 + 2v0)" ), test_expression( 1,"v0 + v1" ), test_expression( 3,"(v0 + v1) * (v0 - v1)" ), test_expression( 3,"2v0 + 3v1" ), test_expression( 3,"2v0 - v1 / 3" ), test_expression( 2,"v0 * v1 / v2" ), test_expression( 3,"2(v0 * v1 / v2)" ), test_expression( 4,"2(v0 / 3 + v1 / 4)" ), test_expression( 3,"(2v0 - v1 / v2)" ), test_expression( 4,"3(2v0 - v1 / v2)" ), test_expression( 5,"7(5v0 * 3v1 / 2v2)" ),
int main(int argc, char* argv[]) { try { // Validate the initially-empty state ... k3d::pipeline_data<k3d::typed_array<k3d::int32_t> > source; test_expression(!source.get()); test_expression(!source); test_expression(source.use_count() == 0); // Validate the state after creating an array ... k3d::typed_array<k3d::int32_t>& source_array = source.create(); test_expression(source.get()); test_expression(source); test_expression(source.use_count() == 1); // Put some data into the array ... source_array.push_back(1); source_array.push_back(2); source_array.push_back(4); // Confirm that read-write access to the array doesn't cause reallocation ... const k3d::typed_array<k3d::int32_t>* before = source.get(); k3d::typed_array<k3d::int32_t>& mutable_source = source.writable(); const k3d::typed_array<k3d::int32_t>* after = source.get(); test_expression(before == after); test_expression(source.use_count() == 1); // Validate the state after creating a shared instance ... k3d::pipeline_data<k3d::typed_array<k3d::int32_t> > modifier(source); test_expression(modifier.get()); test_expression(modifier); test_expression(source.use_count() == 2); test_expression(modifier.use_count() == 2); test_expression(source.get() == modifier.get()); // Validate the state after creating a second shared instance ... k3d::pipeline_data<k3d::typed_array<k3d::int32_t> > sink(modifier); test_expression(sink.get()); test_expression(sink); test_expression(source.use_count() == 3); test_expression(modifier.use_count() == 3); test_expression(sink.use_count() == 3); test_expression(source.get() == sink.get()); test_expression(modifier.get() == sink.get()); // Validate that read-write access from a shared instance reallocates ... k3d::typed_array<k3d::int32_t>& mutable_modifier = modifier.writable(); test_expression(modifier.get()); test_expression(modifier); test_expression(source.use_count() == 2); test_expression(modifier.use_count() == 1); test_expression(sink.use_count() == 2); test_expression(source.get() != modifier.get()); test_expression(modifier.get() != sink.get()); test_expression(source.get() == sink.get()); test_expression(*source == *modifier); // Validate that assignment re-synchronizes the second and third shared instances ... sink = modifier; test_expression(sink.get()); test_expression(sink); test_expression(source.use_count() == 1); test_expression(modifier.use_count() == 2); test_expression(sink.use_count() == 2); test_expression(source.get() != modifier.get()); test_expression(modifier.get() == sink.get()); test_expression(source.get() != sink.get()); test_expression(*modifier == *sink); std::vector<k3d::pipeline_data<k3d::int32_t> > a; a.push_back(k3d::pipeline_data<k3d::int32_t>()); a[0].create(); a[0].writable() = 5; test_expression(*a[0] == 5); const std::vector<k3d::pipeline_data<k3d::int32_t> >& b = a; test_expression(*b[0] == 5); } catch(std::exception& e) { std::cerr << "uncaught exception: " << e.what() << std::endl; return 1; } catch(...) { std::cerr << "unknown exception" << std::endl; } return 0; }