void SatisfyTechRequirement::update() { printDebugInfo("Update"); if (complete) return; if (!assigned) { assign(); return; } if (!acting && assigned) { act(); return; } if (acting) { if (util::game::canResearch(techType)) succeed(); } printDebugInfo("Update End"); }
static void test_footer(void) { memcrap(buffer, sizeof(buffer)); expect(lzma_stream_footer_encode(&known_flags, buffer) == LZMA_OK); succeed(test_footer_decoder(LZMA_OK)); }
void TempDirDeleter::onStart() { if (QDir(cTempDir()).removeRecursively()) { emit succeed(); } else { emit failed(); } }
void FaceIdFetcher::onQuerySuccess(const ndn::ConstBufferPtr& data, const FaceUri& canonicalUri) { size_t offset = 0; bool isOk = false; ndn::Block block; std::tie(isOk, block) = ndn::Block::fromBuffer(data, offset); if (!isOk) { if (m_allowCreate) { startFaceCreate(canonicalUri); } else { fail("Fail to find faceId"); } } else { try { ndn::nfd::FaceStatus status(block); succeed(status.getFaceId()); } catch (const ndn::tlv::Error& e) { std::string errorMessage(e.what()); fail("ERROR: " + errorMessage); } } }
bool HardwareAccel::extractData(VideoFrame& input) { try { auto inFrame = input.pointer(); if (inFrame->format != format_) { std::stringstream buf; buf << "Frame format mismatch: expected " << av_get_pix_fmt_name(format_); buf << ", got " << av_get_pix_fmt_name((AVPixelFormat)inFrame->format); throw std::runtime_error(buf.str()); } // FFmpeg requires a second frame in which to transfer the data // from the GPU buffer to the main memory auto output = std::unique_ptr<VideoFrame>(new VideoFrame()); auto outFrame = output->pointer(); outFrame->format = AV_PIX_FMT_YUV420P; extractData(input, *output); // move outFrame into inFrame so the caller receives extracted image data // but we have to delete inFrame first av_frame_unref(inFrame); av_frame_move_ref(inFrame, outFrame); } catch (const std::runtime_error& e) { fail(false); RING_ERR("%s", e.what()); return false; } succeed(); return true; }
void ColorScanAction::endActionFinished(bool result) { AbstractAction *action = qobject_cast<AbstractAction*>(sender()); endSubAction(action); succeed(); }
int main() { __block int var = 0; int shouldbe = 0; void (^b)(void) = ^{ var++; /*printf("var is at %p with value %d\n", &var, var);*/ }; __typeof(b) _b; //printf("before copy...\n"); b(); ++shouldbe; size_t i; for (i = 0; i < 10; i++) { _b = Block_copy(b); // make a new copy each time assert(_b); ++shouldbe; _b(); // should still update the stack Block_release(_b); } //printf("after...\n"); b(); ++shouldbe; if (var != shouldbe) { fail("var is %d but should be %d", var, shouldbe); } succeed(__FILE__); }
void test_matches(const std::string& proto_key, const LLSD& possibles, const char** begin, const char** end) { std::set<std::string> succeed(begin, end); LLSD prototype(possibles[proto_key]); for (LLSD::map_const_iterator pi(possibles.beginMap()), pend(possibles.endMap()); pi != pend; ++pi) { std::string match(llsd_matches(prototype, pi->second)); std::set<std::string>::const_iterator found = succeed.find(pi->first); if (found != succeed.end()) { // This test is supposed to succeed. Comparing to the // empty string ensures that if the test fails, it will // display the string received so we can tell what failed. ensure_equals("match", match, ""); } else { // This test is supposed to fail. If we get a false match, // the string 'match' will be empty, which doesn't tell us // much about which case went awry. So construct a more // detailed description string. ensure(proto_key + " shouldn't match " + pi->first, ! match.empty()); } } }
void Scout::update() { printDebugInfo("Update"); if (complete) return; if (BWAPI::Broodwar->getFrameCount() - target->getLastVisited() < 5) { succeed(); return; } if (!assigned) { assign(); return; } if (coalition->isActive()) { act(); return; } printDebugInfo("Update End"); }
result_t options_get(int argc, char ** argv, options_t * const options) { char *v, **envp; unsigned int n, i; if (argc < 2) fail_with_message("program path not specified"); options->program_path = argv[1]; if (argc < 3) fail_with_message("program arguments not specified"); options->program_arguments = argv + 2; if (!env_get(JD_MAX_USER_TIME, &v)) fail_with_message(ENV_VAR_NOT_SET, JD_MAX_USER_TIME); if (!string_to_unsigned_int(v, &options->resource_limits.max_user_time_in_seconds)) fail_with_message(ENV_VAR_INVALID, JD_MAX_USER_TIME); if (!env_get(JD_MAX_CPU_TIME, &v)) fail_with_message(ENV_VAR_NOT_SET, JD_MAX_CPU_TIME); if (!string_to_unsigned_int(v, &options->resource_limits.max_cpu_time_in_seconds)) fail_with_message(ENV_VAR_INVALID, JD_MAX_CPU_TIME); if (!env_get(JD_MAX_MEM, &v)) fail_with_message(ENV_VAR_NOT_SET, JD_MAX_MEM); if (!string_to_unsigned_int(v, &options->resource_limits.max_memory_in_bytes)) fail_with_message(ENV_VAR_INVALID, JD_MAX_MEM); /* Determine the number of elements in the child environment 'n' by * counting variables in our environment that have prefix JD_ENV. */ for (n=0, envp=environ; *envp!=NULL; envp++) if (!strncmp(*envp, JD_ENV, JD_ENV_LENGTH)) n++; /* Allocate space for n char pointers, plus one for null termination. */ options->program_environment = malloc((n + 1) * sizeof (char *)); if (options->program_environment == NULL) fail_due_to_error("malloc"); /* Fill the array, skipping the JD_ENV prefix. * Example: JD_ENV_PATH=/bin * ^-------> */ for (i=0, envp=environ; *envp!=NULL && i<n; envp++) { if (!strncmp(*envp, JD_ENV, JD_ENV_LENGTH)) options->program_environment[i++] = *envp + JD_ENV_LENGTH; } /* Terminate the array. */ options->program_environment[n] = NULL; succeed(); }
void Window::tempDirDelete() { if (_tempDeleter) return; _tempDeleterThread = new QThread(); _tempDeleter = new TempDirDeleter(_tempDeleterThread); connect(_tempDeleter, SIGNAL(succeed()), this, SLOT(onTempDirCleared())); connect(_tempDeleter, SIGNAL(failed()), this, SLOT(onTempDirClearFailed())); _tempDeleterThread->start(); }
void chap(Ticketreq *tr) { char *secret, *hkey; DigestState *s; char sbuf[SECRETLEN], hbuf[DESKEYLEN]; uchar digest[MD5dlen]; char chal[CHALLEN]; OChapreply reply; /* * Create a challenge and send it. */ randombytes((uchar*)chal, sizeof(chal)); write(1, chal, sizeof(chal)); /* * get chap reply */ if(readn(0, &reply, sizeof(reply)) < 0) exits(0); safecpy(tr->uid, reply.uid, sizeof(tr->uid)); /* * lookup */ secret = findsecret(KEYDB, tr->uid, sbuf); hkey = findkey(KEYDB, tr->hostid, hbuf); if(hkey == 0 || secret == 0){ replyerror("chap-fail bad response %s", raddr); logfail(tr->uid); exits(0); } /* * check for match */ s = md5(&reply.id, 1, 0, 0); md5((uchar*)secret, strlen(secret), 0, s); md5((uchar*)chal, sizeof(chal), digest, s); if(memcmp(digest, reply.resp, MD5dlen) != 0){ replyerror("chap-fail bad response %s", raddr); logfail(tr->uid); exits(0); } succeed(tr->uid); /* * reply with ticket & authenticator */ if(tickauthreply(tr, hkey) < 0) exits(0); if(debug) syslog(0, AUTHLOG, "chap-ok %s %s", tr->uid, raddr); }
int main(int argc, char *argv[]) { if (argc < 2) fail("To few arguments for test case"); #ifndef ETHR_NO_THREAD_LIB { char *testcase; send_my_pid(); testcase = argv[1]; if (ethr_init(NULL) != 0 || ethr_late_init(NULL) != 0) fail("Failed to initialize the ethread library"); if (strcmp(testcase, "create_join_thread") == 0) create_join_thread_test(); else if (strcmp(testcase, "equal_tids") == 0) equal_tids_test(); else if (strcmp(testcase, "mutex") == 0) mutex_test(); else if (strcmp(testcase, "try_lock_mutex") == 0) try_lock_mutex_test(); else if (strcmp(testcase, "cond_wait") == 0) cond_wait_test(); else if (strcmp(testcase, "broadcast") == 0) broadcast_test(); else if (strcmp(testcase, "detached_thread") == 0) detached_thread_test(); else if (strcmp(testcase, "max_threads") == 0) max_threads_test(); else if (strcmp(testcase, "tsd") == 0) tsd_test(); else if (strcmp(testcase, "spinlock") == 0) spinlock_test(); else if (strcmp(testcase, "rwspinlock") == 0) rwspinlock_test(); else if (strcmp(testcase, "rwmutex") == 0) rwmutex_test(); else if (strcmp(testcase, "atomic") == 0) atomic_test(); else if (strcmp(testcase, "dw_atomic_massage") == 0) dw_atomic_massage_test(); else skip("Test case \"%s\" not implemented yet", testcase); succeed(NULL); } #else /* #ifndef ETHR_NO_THREAD_LIB */ skip("No ethread library to test"); #endif /* #ifndef ETHR_NO_THREAD_LIB */ return 0; }
void FaceIdFetcher::startFaceCreate(const FaceUri& canonicalUri) { ndn::nfd::ControlParameters parameters; parameters.setUri(canonicalUri.toString()); m_controller.start<ndn::nfd::FaceCreateCommand>(parameters, [this] (const ndn::nfd::ControlParameters& result) { succeed(result.getFaceId()); }, bind(&FaceIdFetcher::onFaceCreateError, this, _1, "Face creation failed")); }
int _verify(int cond, char const *teststr, char const *file, int line, char const *func) { if (cond) { succeed(); return cond; } fail("Verification failed (%s)", teststr); return cond; }
int main(int argc __unused, char *argv[]) { voidVoid array[100]; for (int i = 0; i < 100; ++i) { array[i] = testRoutine(argv[0]); array[i](); } for (int i = 0; i < 100; ++i) { Block_release(array[i]); } succeed(__FILE__); }
static result_t start_child(pid_t * const pid, const int master_fd, const int slave_fd, const options_t * const options) { if (!process_create(pid)) fail(); if (*pid == 0) { close(master_fd); run_child(slave_fd, options); } succeed(); }
static result_t start_relay(pid_t * const pid, const int master_fd, const int slave_fd) { if (!process_create(pid)) fail(); if (*pid == 0) { close(slave_fd); run_relay(master_fd); } succeed(); }
int _compare(int value, int expval, char const *act_str, char const *exp_str, char const *file, int line, char const *func) { if (value == expval) { succeed(); return 1; } fail("Actual (%s): %d, Expected (%s): %d", act_str, value, exp_str, expval); return 0; }
void StatusChecker::statusDownloadFinished() { QLOG_DEBUG() << "Finished loading status JSON."; QByteArray data; { ByteArrayDownloadPtr dl = std::dynamic_pointer_cast<ByteArrayDownload>(m_statusNetJob->first()); data = dl->m_data; m_statusNetJob.reset(); } QJsonParseError jsonError; QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); if (jsonError.error != QJsonParseError::NoError) { fail("Error parsing status JSON:" + jsonError.errorString()); return; } if (!jsonDoc.isArray()) { fail("Error parsing status JSON: JSON root is not an array"); return; } QJsonArray root = jsonDoc.array(); for(auto status = root.begin(); status != root.end(); ++status) { QVariantMap map = (*status).toObject().toVariantMap(); for (QVariantMap::const_iterator iter = map.begin(); iter != map.end(); ++iter) { QString key = iter.key(); QVariant value = iter.value(); if(value.type() == QVariant::Type::String) { m_statusEntries.insert(key, value.toString()); //QLOG_DEBUG() << "Status JSON object: " << key << m_statusEntries[key]; } else { fail("Malformed status JSON: expected status type to be a string."); return; } } } succeed(); }
static result_t start_timer(pid_t * const pid, const int master_fd, const int slave_fd, const unsigned int n) { if (!process_create(pid)) fail(); if (*pid == 0) { close(master_fd); close(slave_fd); run_timer(n); } succeed(); }
static void test_corrupt(void) { const size_t alloc_size = 128 * 1024; uint8_t *buf = malloc(alloc_size); expect(buf != NULL); lzma_stream strm = LZMA_STREAM_INIT; lzma_index *i = create_empty(); expect(lzma_index_append(i, NULL, 0, 1) == LZMA_PROG_ERROR); lzma_index_end(i, NULL); // Create a valid Index and corrupt it in different ways. i = create_small(); expect(lzma_index_encoder(&strm, i) == LZMA_OK); succeed(coder_loop(&strm, NULL, 0, buf, 20, LZMA_STREAM_END, LZMA_RUN)); lzma_index_end(i, NULL); // Wrong Index Indicator buf[0] ^= 1; expect(lzma_index_decoder(&strm, &i, MEMLIMIT) == LZMA_OK); succeed(decoder_loop_ret(&strm, buf, 1, LZMA_DATA_ERROR)); buf[0] ^= 1; // Wrong Number of Records and thus CRC32 fails. --buf[1]; expect(lzma_index_decoder(&strm, &i, MEMLIMIT) == LZMA_OK); succeed(decoder_loop_ret(&strm, buf, 10, LZMA_DATA_ERROR)); ++buf[1]; // Padding not NULs buf[15] ^= 1; expect(lzma_index_decoder(&strm, &i, MEMLIMIT) == LZMA_OK); succeed(decoder_loop_ret(&strm, buf, 16, LZMA_DATA_ERROR)); lzma_end(&strm); free(buf); }
void ColorScanAction::checkEnding() { if (_destinationReached && _leftArmState == Scanning && _rightArmState == Scanning) { if (_stopped) failed(); else { if (_endAction) executeSubAction(_endAction); else succeed(); } } }
void ClearManager::onStart() { while (true) { int task = 0; bool result = false; StorageMap images; { QMutexLocker lock(&data->mutex); if (data->tasks.isEmpty()) { data->working = false; break; } task = data->tasks.at(0); images = data->images; } switch (task) { case ClearManagerAll: result = (QDir(cTempDir()).removeRecursively() && QDir(_basePath).removeRecursively()); break; case ClearManagerDownloads: result = QDir(cTempDir()).removeRecursively(); break; case ClearManagerImages: for (StorageMap::const_iterator i = images.cbegin(), e = images.cend(); i != e; ++i) { clearKey(i.value().first, false); } result = true; break; } { QMutexLocker lock(&data->mutex); if (data->tasks.at(0) == task) { data->tasks.pop_front(); if (data->tasks.isEmpty()) { data->working = false; } } if (result) { emit succeed(task, data->working ? 0 : this); } else { emit failed(task, data->working ? 0 : this); } if (!data->working) break; } } }
int solve(){ int i,j; for(i=0;i<tail;i++){ if(succeed(i)){ show(i); return 1; } for(j=0;j<6;j++){ setsit(i); // 将油罐油量设置为节点i的状态 if(action[j]() && !exist()){ //生成新状态并检查是否出现过 //printf("%s\n", act_name); append(i); // 保存新状态 } } } return 0; }
/* Read up to 1kB of data from src and write it to dst. Assumes there is data * waiting to be read on src. */ static result_t relay(const int src, const int dst, unsigned int * const n_r) { char buf[1024]; ssize_t nr; nr = read(src, buf, sizeof buf); if (nr == -1) fail(); if (nr > 0) { ssize_t nw = write(dst, buf, nr); if (nw == -1 || nw != nr) fail(); } if (n_r != NULL) *n_r = nr; succeed(); }
static void max_threads_test(void) { int no_threads[MTT_TIMES], i, up, down, eq, res; char *str; res = ethr_mutex_init(&mtt_mutex); ASSERT(res == 0); res = ethr_cond_init(&mtt_cond); ASSERT(res == 0); for (i = 0; i < MTT_TIMES; i++) { no_threads[i] = mtt_create_join_threads(); } str = &mtt_string[0]; eq = up = down = 0; for (i = 0; i < MTT_TIMES; i++) { if (i == 0) { str += sprintf(str, "%d", no_threads[i]); continue; } str += sprintf(str, ", %d", no_threads[i]); if (no_threads[i] < no_threads[i-1]) down++; else if (no_threads[i] > no_threads[i-1]) up++; else eq++; } print_line("Max created threads: %s", mtt_string); /* We fail if the no of threads we are able to create constantly decrease */ ASSERT(!down || up || eq); succeed("Max created threads: %s", mtt_string); }
int main() { struct stuff { long int a; long int b; long int c; } localStuff = { 10, 20, 30 }; int d = 0; void (^a)(void) = ^ { printf("d is %d", d); }; void (^b)(void) = ^ { printf("d is %d, localStuff.a is %lu", d, localStuff.a); }; unsigned long nominalsize = Block_size(b) - Block_size(a); #if __cplusplus__ // need copy+dispose helper for C++ structures nominalsize += 2*sizeof(void*); #endif if ((Block_size(b) - Block_size(a)) != nominalsize) { testwarn("dump of b is %s", _Block_dump(b)); fail("sizeof a is %lu, sizeof b is %lu, expected %lu", Block_size(a), Block_size(b), nominalsize); } succeed(__FILE__); }
//-------------核心代码--------------// int solve() { int i, j; queue[0].ca=Ja.val; queue[0].cb=Jb.val; queue[0].parent=-1; for (i = 0; i<tail; i++){ if (succeed(i)){ //找到目标状态 show(i); //递归打印出达到目标状态的操作组序列 return 1; } for (j = 0; j<6; j++){ Ja.val=queue[i].ca; Jb.val=queue[i].cb;//将油罐油量设置为节点i的状态 if (action[j]() && !exist(i)) {//执行j判断并检查是否重复 ans[i].parent=i; ans[i].ca=Ja.val; ans[i].cb=Jb.val; ans[i].act=name[j]; put_node(ans[i]); //j操作后的状态加入队列中 } } } return 0; }
static void test_decode_invalid(void) { known_flags.check = LZMA_CHECK_NONE; known_flags.backward_size = 1024; expect(lzma_stream_header_encode(&known_flags, buffer) == LZMA_OK); // Test 1 (invalid Magic Bytes) buffer[5] ^= 1; succeed(test_header_decoder(LZMA_FORMAT_ERROR)); buffer[5] ^= 1; // Test 2a (valid CRC32) uint32_t crc = lzma_crc32(buffer + 6, 2, 0); unaligned_write32le(buffer + 8, crc); succeed(test_header_decoder(LZMA_OK)); // Test 2b (invalid Stream Flags with valid CRC32) buffer[6] ^= 0x20; crc = lzma_crc32(buffer + 6, 2, 0); unaligned_write32le(buffer + 8, crc); succeed(test_header_decoder(LZMA_OPTIONS_ERROR)); // Test 3 (invalid CRC32) expect(lzma_stream_header_encode(&known_flags, buffer) == LZMA_OK); buffer[9] ^= 1; succeed(test_header_decoder(LZMA_DATA_ERROR)); // Test 4 (invalid Stream Flags with valid CRC32) expect(lzma_stream_footer_encode(&known_flags, buffer) == LZMA_OK); buffer[9] ^= 0x40; crc = lzma_crc32(buffer + 4, 6, 0); unaligned_write32le(buffer, crc); succeed(test_footer_decoder(LZMA_OPTIONS_ERROR)); // Test 5 (invalid Magic Bytes) expect(lzma_stream_footer_encode(&known_flags, buffer) == LZMA_OK); buffer[11] ^= 1; succeed(test_footer_decoder(LZMA_FORMAT_ERROR)); }