module& module::set_input_rollback(Record_info &op_info) { net* tar_net = op_info.net_ref; bool value = !op_info.value_set; if (!_set_input(tar_net, value)) throw exception("rollback set input failed. (set_input_rollback)"); return *this; }
/* * Set input string * @param input input string * @param is_file true if file, false otherwise * @return true on success, false otherwise */ bool _par::set_input( const std::string &input, bool is_file ) { return _set_input( input, is_file ); }
static void test1() { struct KeyVal *kv; _check_err(KeyVal_new(&kv), "KeyVal_new"); // 1a: missing file remove(IN); _check_load_return(kv, 2, "1a. detects missing input file"); // 1b: file with complete crap in it _set_input("this file has complete crap in it\n"); _check_load_return(kv, 1, "1b. detects complete crap"); // 1c: file with EOF in key _set_input("`key"); _check_load_return(kv, 1, "1c. detects EOF in key"); // 1d/1e: file with missing "=" or "remove" _set_input("`key`\n"); _check_load_return(kv, 1, "1d. detects '\\n' instead of '=' or 'remove'"); _set_input("`key`"); _check_load_return(kv, 1, "1e. detects EOF instead of '=' or 'remove'"); // 1f: file with "foo" instead of "=" or "remove" _set_input("`key` foo"); _check_load_return(kv, 1, "1f. detects crap instead of '=' or 'remove'"); // 1g/1h: file with missing value _set_input("`key` =\n"); _check_load_return(kv, 1, "1g. detects '\\n' instead of value"); _set_input("`key` ="); _check_load_return(kv, 1, "1h. detects EOF instead of value"); // 1i: file with EOF in value _set_input("`key` = `val"); _check_load_return(kv, 1, "1i. detects EOF in value (missing close-quote)"); // 1j: file with comment after value (sorry, not allowed!) _set_input("`key` = `val` #moo!"); _check_load_return(kv, 1, "1j. detects comment after value"); _check_err(KeyVal_delete(kv), "KeyVal_delete"); }
module& module::set_input(net* tar_net, bool value) { if (tar_net == NULL) throw exception("NULL net specified. (set_input)"); if (!_set_input(tar_net, value)) throw exception(("setting " + tar_net->get_net_name() + ((value)? "" : " not") + " as input failed. (set_input)").c_str()); Record new_record; new_record.op_type = SI; new_record.op_info.net_ref = tar_net; new_record.op_info.value_set = value; lRecordLst.push_back(new_record); return *this; }
static void test2() { struct KeyVal *kv; _check_err(KeyVal_new(&kv), "KeyVal_new"); // 2a: file with nothing in it FILE *fh = fopen(IN, "w"); fclose(fh); _check_load_return(kv, 0, "2a. empty input file"); // 2b: file with only whitespace _set_input(" \t \t \n\t\t \n\n "); // also tests missing \n at EOF _check_load_return(kv, 0, "2b. whitespace-only input file"); // 2c: file with only comments _set_input("# nothing\n# at all!\n"); _check_load_return(kv, 0, "2c. comment-only input file"); // 2d: save it out; should get nothing _check_err(KeyVal_save(kv, OUT, 0, 0), "KeyVal_save"); ok(_check_output("") == 0, "2d. writing out empty input generates empty output"); _check_err(KeyVal_delete(kv), "KeyVal_delete"); }
static void test5() { struct KeyVal *kv; _check_err(KeyVal_new(&kv), "KeyVal_new"); // 5a: key and val with escaped quote. Input should look like this: // `\`key\\` = `\\val\`` // `key\`\`key` = `val\\\\val` const char *TEXT = "`\\`key\\\\` = `\\\\val\\``\n`key\\`\\`key` = `val\\\\\\\\val`\n"; _set_input(TEXT); if (!ok(KeyVal_load(kv, IN) == 0, "5a. reads escapes ok")) return; // 5b. escapes on the outside of key: char *value; _check_err(KeyVal_getValue(&value, kv, "`key\\", 0), "KeyVal_getValue"); if (ok(value != 0, "5b. key with escapes at start and end")) { // 5c. escapes on the outsides of value: ok(strcmp(value, "\\val`") == 0, "5c. value with escapes at start and end"); } // 5d. (consecutive) escapes in the middle of key: _check_err(KeyVal_getValue(&value, kv, "key``key", 0), "KeyVal_getValue"); if (ok(value != 0, "5d. key with consecutive escapes in middle")) { // 5e. (consecutive) escapes in the middle of value: ok(strcmp(value, "val\\\\val") == 0, "5e. value with consecutive escapes in middle"); } // 5f. write out this nastiness: _check_err(KeyVal_save(kv, OUT, 0, 0), "KeyVal_save"); ok(_check_output(TEXT) == 0, "5f. escapes write out correctly"); _check_err(KeyVal_delete(kv), "KeyVal_delete"); }
static void test3() { struct KeyVal *kv; _check_err(KeyVal_new(&kv), "KeyVal_new"); // 3a: unloaded kv should be empty: unsigned long size; _check_err(KeyVal_size(&size, kv), "KeyVal_size"); ok(size == 0, "3a. uninitialized KeyVal empty"); // 3b: single-element file _set_input("`key` = `val`\n"); // minimal typical input if (!ok(KeyVal_load(kv, IN) == 0, "3b. reads single-element input")) return; // 3c: size set from file input _check_err(KeyVal_size(&size, kv), "KeyVal_size"); ok(size == 1, "3c. size of single-element input is 1"); // 3d: search for element before it: char *value; _check_err(KeyVal_getValue(&value, kv, "asdf", 0), "KeyVal_getValue"); if (!ok(value == 0, "3d. search for nonexistent 'asdf'")) { printf(" - instead found '%s'!\n", value); } // 3e: search for element after it: _check_err(KeyVal_getValue(&value, kv, "zxcv", 0), "KeyVal_getValue"); ok(value == 0, "3e. search for nonexistent 'zxcv'"); // 3f: search for it itself: _check_err(KeyVal_getValue(&value, kv, "key", 0), "KeyVal_getValue"); if (ok(value != 0, "3f. search for existing 'key'")) { // 3g: has the right value: ok(strcmp(value, "val") == 0, "3g. 'key' has value 'val'"); } // 3h: search for subset key: _check_err(KeyVal_getValue(&value, kv, "ke", 0), "KeyVal_getValue"); if (!ok(value == 0, "3h. search for subset 'ke'")) { printf(" - instead found '%s'!\n", value); } // 3i: search for superset key: _check_err(KeyVal_getValue(&value, kv, "keysha", 0), "KeyVal_getValue"); ok(value == 0, "3i. search for superset 'keysha'"); // 3j: getKeys returns one thing char ** keys; _check_err(KeyVal_getKeys(&keys, kv, ""), "KeyVal_getKeys"); if (keys) { if (!ok(keys[0]!=0 && !strcmp(keys[0], "key") && keys[1]==0, "3j. getKeys returns ['key']")) { printf("keys returned:\n"); for (char **f = keys; *f; ++f) { printf(" '%s'\n", *f); } } for (char **f = keys; *f; ++f) { free(*f); } free(keys); } else { printf("[UNEXPECTED-1] getKeys should never return a null result"); } // 3k: hasValue should find it: unsigned char boolflag; _check_err(KeyVal_hasValue(&boolflag, kv, "key"), "KeyVal_hasValue"); ok(boolflag == 1, "3k. hasValue finds 'key'"); // 3l: hasKeys should not segfault on it: _check_err(KeyVal_hasKeys(&boolflag, kv, "key"), "KeyVal_hasKeys"); ok(boolflag == 0, "3l. hasKeys does not segfault on last element, and doesn't report 'key'"); // 3m: exists should also find it: _check_err(KeyVal_exists(&boolflag, kv, "key"), "KeyVal_exists"); ok(boolflag == 1, "3m. exists finds 'key'"); // 3n: save it out; should get single value _check_err(KeyVal_save(kv, OUT, 0, 0), "KeyVal_save"); ok(_check_output("`key` = `val`\n") == 0, "3n. writes out the single value"); // 3o: removing element before: _check_err(KeyVal_remove(kv, "asdf"), "KeyVal_remove"); _check_err(KeyVal_size(&size, kv), "KeyVal_size"); ok(size == 1, "3o. removing nonexistent 'asdf'"); // 3p: removing element after: _check_err(KeyVal_remove(kv, "zxcv"), "KeyVal_remove"); _check_err(KeyVal_size(&size, kv), "KeyVal_size"); ok(size == 1, "3p. removing nonexistent 'zxcv'"); // 3q: removing element: _check_err(KeyVal_remove(kv, "key"), "KeyVal_remove"); _check_err(KeyVal_size(&size, kv), "KeyVal_size"); ok(size == 0, "3q. removing 'key'"); // 3r: getKeys returns nothing _check_err(KeyVal_getKeys(&keys, kv, ""), "KeyVal_getKeys"); if (keys) { ok(keys[0] == 0, "3r: getKeys now returns ['']"); free(keys); } else { printf("[UNEXPECTED-2] getKeys should never return a null result"); } // 3s: save it out; should get nothing now _check_err(KeyVal_save(kv, OUT, 0, 0), "KeyVal_save"); ok(_check_output("") == 0, "3s. writes out empty file"); _check_err(KeyVal_delete(kv), "KeyVal_delete"); }
// Set pin as input static inline void Pin_Input(struct _pin_t pin) { _set_input(pin.port, pin.mask); }