static void test_bswap(void *p) { int_check(bswap16(0xff01), 0x01ff); int_check(bswap32(0x01020304), 0x04030201); int_check(bswap64(0x0102030405060708ULL), 0x0807060504030201ULL); end:; }
void test_rsac2() { int err; float y[1024], x[1024]; int lnpts, max; err = SAC_OK; ok(err == SAC_OK, "error_code"); ok(cmhdr.fundef == SAC_FLOAT_UNDEFINED, " Header Float is undefined"); max = 1024; /* Unknown file */ rsac2(FILE_UNKNOWN, &(y[0]), &lnpts, &(x[0]), &max, &err, strlen(FILE_UNKNOWN)); int_check(err, 108, "rsac2 unknown file"); /* Length too short */ rsac2(FILE_UNKNOWN, &(y[0]), &lnpts, &(x[0]), &max, &err, strlen(FILE_UNKNOWN)-1); int_check(err, 108, "rsac2 unknown file"); /* Length too long */ rsac2(FILE_UNKNOWN, &(y[0]), &lnpts, &(x[0]), &max, &err, strlen(FILE_UNKNOWN) * 10); int_check(err, 108, "rsac2 unknown file"); /* Length < 0 */ rsac2(FILE_UNKNOWN, &(y[0]), &lnpts, &(x[0]), &max, &err, strlen(FILE_UNKNOWN)); int_check(err, 108, "rsac2 unknown file"); test_rsac2_file(FILE_SMALL_UNEVEN); test_rsac2_file(FILE_BIG_UNEVEN); }
int main(){ double temperature = 0; // 気温 char unit; // 単位 double result; cout << "気温を入力してください。(c: 摂氏, f: 華氏)" << endl; while(cin >> temperature >> unit){ switch(unit){ case 'c': if(!int_check(ctof(temperature))) error("int型で表すことができません。"); cout << " -> " << (int)ctof(temperature) << "℉" << endl; break; case 'f': if(!int_check(ftoc(temperature))) error("int型で表すことができません。"); cout << " -> " << (int)ftoc(temperature) << "℃" << endl; break; default: cout << "そのような単位は入力できません。" << endl; break; } } }
static void test_pow2(void *p) { int_check(is_power_of_2(0), 0); int_check(is_power_of_2(1), 1); int_check(is_power_of_2(2), 1); int_check(is_power_of_2(3), 0); end:; }
void f_band(union argument *arg) { struct value a, b; (void) arg; /* avoid -Wunused warning */ int_check(pop(&b)); int_check(pop(&a)); push(Ginteger(&a, a.v.int_val & b.v.int_val)); }
static void test_ror(void *p) { /* ror16 */ int_check(ror16(1, 1), 0x8000); /* ror32 */ int_check(ror32(1, 1), 0x80000000); /* ror64 */ ull_check(ror64(1, 1), 0x8000000000000000ULL); end:; }
static void test_rol(void *p) { /* rol16 */ int_check(rol16(1, 1), 2); int_check(rol16(1, 15), 32768); int_check(rol16(0x8000, 1), 1); /* rol32 */ int_check(rol32(1, 1), 2); int_check(rol32(0x80000000, 1), 1); /* rol64 */ ull_check(rol64(1, 1), 2); ull_check(rol64(1, 63), 0x8000000000000000); end:; }
void f_bnot(union argument *arg) { struct value a; (void) arg; /* avoid -Wunused warning */ int_check(pop(&a)); push(Ginteger(&a, ~a.v.int_val)); }
static void test_fsize(void *p) { int_check(createfile(), 1); tt_assert(file_size(filename) == (int)strlen(fdata)); tt_assert(file_size(filename) == (int)sizeof(fdata) - 1); tt_assert(file_size("nonexist") == -1); end:; }
static void test_json_iter(void *p) { struct JsonContext *ctx; struct JsonValue *list, *dict; const char *json = "{\"3\": 3, \"1\": 1, \"2\": 2}"; const char *json2 = "[1,2,3]"; int counter; ctx = json_new_context(NULL, 128); tt_assert(ctx); dict = json_parse(ctx, json, strlen(json)); tt_assert(dict); int_check(json_value_size(dict), 3); counter = 1; tt_assert(json_dict_iter(dict, dict_walker, &counter)); list = json_parse(ctx, json2, strlen(json2)); tt_assert(list); int_check(json_value_size(list), 3); counter = 1; tt_assert(json_list_iter(list, list_walker, &counter)); end: json_free_context(ctx); }
static void test_crc32(void *p) { int_check(xcrc32(""), 0); int_check(xcrc32("a"), 3904355907); int_check(xcrc32("abc"), 891568578); int_check(xcrc32("message digest"), 538287487); int_check(xcrc32("abcdefghijklmnopqrstuvwxyz"), 1277644989); int_check(xcrc32("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 532866770); int_check(xcrc32("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 2091469426); end:; }
static void test_mdict(void *p) { struct MDict *d; struct MBuf buf; const char *s; d = mdict_new(NULL); str_check(xget(d, "key"), "NULL"); int_check(mdict_put(d, "key", "val"), 1); int_check(mdict_put(d, "key2", "foo"), 1); int_check(mdict_put(d, "key2", ""), 1); int_check(mdict_put(d, "key3", NULL), 1); int_check(mdict_put(d, "key4", "v1"), 1); int_check(mdict_del(d, "key4"), 1); str_check(xget(d, "key"), "val"); str_check(xget(d, "key2"), ""); str_check(xget(d, "key3"), "NULL"); str_check(xget(d, "key4"), "NULL"); str_check(xget(d, "key5"), "NULL"); int_check(mdict_del(d, "key5"), 0); mbuf_init_dynamic(&buf); int_check(mdict_urlencode(d, &buf), 1); int_check(mbuf_write_byte(&buf, 0), 1); str_check(mbuf_data(&buf), "key=val&key2=&key3"); mbuf_free(&buf); mdict_free(d); d = mdict_new(NULL); s = "key=val&key2=&key3"; int_check(mdict_urldecode(d, s, strlen(s)), 1); str_check(xget(d, "key"), "val"); str_check(xget(d, "key2"), ""); str_check(xget(d, "key3"), "NULL"); mdict_free(d); end:; }
void aic6250_device::int_msk_reg_0_w(u8 data) { LOGMASKED(LOG_REG, "int_msk_reg_0_w 0x%02x\n", data); /* * Writing a zero to Bits 0 and 1 of this register will reset the selected * or reselected interrupt status in Status Register 1 (Register 08), * causing the interrupt status to be lost. */ if (!(data & R03W_EN_SELECT_INT)) m_status_reg_1 &= ~R08R_SELECTED; if (!(data & R03W_EN_RESEL_INT)) m_status_reg_1 &= ~R08R_RESELECTED; /* * This bit will be reset to 0 when the Enable Command Done interrupt bit (Reg 03, Bit 3) is set to zero. */ if (!(data & R03W_EN_CMD_DONE_INT)) m_status_reg_1 &= ~R08R_CMD_DONE; if ((m_int_msk_reg_0 ^ data) & R03W_ARB_SEL_START) { if (data & R03W_ARB_SEL_START) { if (m_state != IDLE) fatalerror("attempted to start selection while not idle\n"); m_state = ARB_BUS_FREE; m_state_timer->adjust(attotime::zero); } else { if (m_state == IDLE) fatalerror("attempted to abort selection while idle\n"); m_state = IDLE; } } m_int_msk_reg_0 = data; int_check(); }
static void test_strpool(void *p) { struct StrPool *pool; struct PStr *s; pool = strpool_create(NULL); tt_assert(pool); strpool_free(pool); pool = strpool_create(NULL); tt_assert(pool); int_check(strpool_total(pool), 0); s = strpool_get(pool, "foo", -1); str_check(s->str, "foo"); int_check(s->refcnt, 1); int_check(s->len, 3); int_check(strpool_total(pool), 1); tt_assert(s == strpool_get(pool, "fooTAIL", 3)); int_check(s->refcnt, 2); int_check(strpool_total(pool), 1); strpool_incref(s); int_check(s->refcnt, 3); strpool_decref(s); int_check(s->refcnt, 2); strpool_decref(s); int_check(s->refcnt, 1); int_check(strpool_total(pool), 1); strpool_decref(s); int_check(strpool_total(pool), 0); strpool_free(pool); /* free strc with strings */ pool = strpool_create(NULL); tt_assert(pool); s = strpool_get(pool, "foo", -1); s = strpool_get(pool, "bar", 3); int_check(strpool_total(pool), 2); strpool_free(pool); end:; }
void test_rsac2_header_file(int vnpts, float vend) { float_check(*b, 0.10, "b"); float_check(*begin, 0.10, "begin"); float_check(*e, vend, "e"); float_check(*ennd, vend, "ennd"); float_undef(*delta, "delta"); float_check(*depmax, 0.904837, "depmax"); float_check(*depmin, 0.0, "cmpinc"); float_check(*depmx, 0.904837, "depmax"); float_check(*depmn, 0.0, "depmn"); ok(fabs(*depmen - 0.080868) < 1e-4, "depmen value (value %f, expected %f diff %e)", *depmen, 0.01, fabs(*depmen - 0.01)); ok(fabs(*fmean - 0.080868) < 1e-4, "fmean value (value %f, expected %f diff %e)", *fmean, 0.01, fabs(*fmean - 0.01)); float_undef(*a, "a"); float_undef(*az, "az"); float_undef(*baz, "baz"); float_undef(*cmpinc, "cmpinc"); float_undef(*cmpaz, "cmpaz"); float_undef(*dist, "dist"); float_undef(*evdp, "evdp"); float_undef(*evla, "evla"); float_undef(*evlo, "evlo"); float_undef(*evel, "evel"); float_undef(*f, "f"); float_undef(*fini, "fini"); float_undef(*fhdr64, "fhdr64"); float_undef(*fhdr65, "fhdr65"); float_undef(*fhdr66, "fhdr66"); float_undef(*fhdr67, "fhdr67"); float_undef(*fhdr68, "fhdr68"); float_undef(*fhdr69, "fhdr69"); float_undef(*fhdr70, "fhdr70"); float_undef(*fmt, "fmt"); float_undef(*gcarc, "gcarc"); int_undef(*idep, "idep"); int_undef(*ievreg, "ievreg"); int_undef(*ievtyp, "ievtyp"); int_check(*iftype, 1, "file type"); int_undef(*imagtyp, "imagtyp"); int_undef(*imagsrc, "imagsrc"); int_undef(*ihdr13, "ihdr13"); int_undef(*ihdr14, "ihdr14"); int_undef(*ihdr15, "ihdr15"); int_undef(*ihdr16, "ihdr16"); int_undef(*ihdr17, "ihdr17"); int_undef(*ihdr18, "ihdr18"); int_undef(*ihdr19, "ihdr19"); int_undef(*ihdr20, "ihdr20"); int_undef(*ihdr4, "ihdr4"); int_undef(*iinst, "iinst"); int_undef(*iqual, "iqual"); int_undef(*istreg, "istreg"); int_undef(*isynth, "isynth"); int_undef(*iztype, "iztype"); char_check(kstnm, "sta ", kstnm); char_undef(kevnm,"kevnm"); char_undef(khole, "khole"); char_undef(ka, "ka"); char_undef(ko, "ko"); char_undef(kt0, "kt0"); char_undef(kt1, "kt1"); char_undef(kt2, "kt2"); char_undef(kt3, "kt3"); char_undef(kt4, "kt4"); char_undef(kt5, "kt5"); char_undef(kt6, "kt6"); char_undef(kt7, "kt7"); char_undef(kt8, "kt8"); char_undef(kt9, "kt9"); char_undef(kf, "kf"); char_undef(kuser0, "kuser0"); char_undef(kuser1, "kuser1"); char_undef(kuser2, "kuser2"); char_check(kcmpnm, "Q ", "kcmpnm"); char_undef(knetwk, "knetwk"); char_undef(kdatrd, "kdatrd"); char_undef(kinst, "kinst"); int_check(*lcalda, 1, "lcalda"); int_check(*leven, 0, "leven"); int_check(*lhdr5, 0, "lhdr5"); int_check(*lovrok, 1, "lovrok"); int_check(*lpspol, 0, "lpspol"); int_undef(*nevid, "nevid"); int_undef(*nhdr15, "nhdr15"); int_undef(*norid, "norid"); int_check(*npts, vnpts, "npts"); int_check(*nvhdr, 6, "nvhdr"); int_undef(*nwfid, "nwfid"); int_undef(*nxsize, "nxsize"); int_undef(*nysize, "nysize"); int_undef(*nzdttm, "nzdttm"); int_undef(*nzjday, "nzjday"); int_undef(*nzmin, "nzmin"); int_undef(*nzmsec, "nzmsec"); int_undef(*nzsec, "nzsec"); int_undef(*nzyear, "nzyear"); float_undef(*o, "o"); float_undef(*odelta, "odelta"); float_undef(*origin, "origin"); float_undef(*resp0, "resp0"); float_undef(*resp1, "resp1"); float_undef(*resp2, "resp2"); float_undef(*resp3, "resp3"); float_undef(*resp4, "resp4"); float_undef(*resp5, "resp5"); float_undef(*resp6, "resp6"); float_undef(*resp7, "resp7"); float_undef(*resp8, "resp8"); float_undef(*resp9, "resp9"); float_undef(*sb, "sb"); float_undef(*scale, "scale"); float_undef(*sdelta, "sdelta"); float_undef(*stdp, "stdp"); float_undef(*stel, "stel"); float_undef(*stla, "stla"); float_undef(*stlo, "stlo"); float_undef(*t0, "t0"); float_undef(*t1, "t1"); float_undef(*t2, "t2"); float_undef(*t3, "t3"); float_undef(*t4, "t4"); float_undef(*t5, "t5"); float_undef(*t6, "t6"); float_undef(*t7, "t7"); float_undef(*t8, "t8"); float_undef(*t9, "t9"); float_undef(*time0, "time0"); float_undef(*time1, "time1"); float_undef(*time2, "time2"); float_undef(*time3, "time3"); float_undef(*time4, "time4"); float_undef(*time5, "time5"); float_undef(*time6, "time6"); float_undef(*time7, "time7"); float_undef(*time8, "time8"); float_undef(*time9, "time9"); float_undef(*user0, "user0"); float_undef(*user1, "user1"); float_undef(*user2, "user2"); float_undef(*user3, "user3"); float_undef(*user4, "user4"); float_undef(*user5, "user5"); float_undef(*user6, "user6"); float_undef(*user7, "user7"); float_undef(*user8, "user8"); float_undef(*user9, "user9"); float_undef(*xmaximum, "xmaximum"); float_undef(*xminimum, "xminimum"); float_undef(*ymaximum, "ymaximum"); float_undef(*yminimum, "yminimum"); }
static void test_lookup3(void *p) { #ifdef WORDS_BIGENDIAN int_check(xlookup3(""), 3735928559); int_check(xlookup3("a"), -454251968); int_check(xlookup3("abc"), -1186250080); int_check(xlookup3("message digest"), 670730672); int_check(xlookup3("abcdefghijklmnopqrstuvwxyz"), 251682059); int_check(xlookup3("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 567386262); int_check(xlookup3("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 312582506); #else int_check(xlookup3(""), 3735928559); int_check(xlookup3("a"), 1490454280); int_check(xlookup3("abc"), 238646833); int_check(xlookup3("message digest"), 2512672053); int_check(xlookup3("abcdefghijklmnopqrstuvwxyz"), 1966650813); int_check(xlookup3("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 3992286962); int_check(xlookup3("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), 2776963519); #endif end:; }
static void test_ffs(void *p) { /* ffs */ int_check(ffs(0), 0); int_check(ffs(1), 1); int_check(ffs(3), 1); int_check(ffs((int)-1), 1); int_check(ffs(ror32(1,1)), 32); /* flsl */ int_check(ffsl(0), 0); int_check(ffsl(1), 1); int_check(ffsl(3), 1); int_check(ffsl((long)-1), 1); if (sizeof(long) == 4) int_check(ffsl(ror32(1,1)), 32); else int_check(ffsl(ror64(1,1)), 64); /* ffsll */ int_check(ffsll(0), 0); int_check(ffsll(1), 1); int_check(ffsll(3), 1); int_check(ffsll((long long)-1), 1); ull_check((1ULL << 63), ror64(1,1)); int_check(ffsll(1ULL << 63), 64); int_check(ffsll(ror64(1,1)), 64); end:; }
static void test_fls(void *p) { /* fls */ int_check(fls(0), 0); int_check(fls(1), 1); int_check(fls(3), 2); int_check(fls((int)-1), 32); /* flsl */ int_check(flsl(0), 0); int_check(flsl(1), 1); int_check(flsl(3), 2); if (sizeof(long) == 4) int_check(flsl((long)-1), 32); else int_check(flsl((long)-1), 64); /* flsll */ int_check(flsll(0), 0); int_check(flsll(1), 1); int_check(flsll(3), 2); int_check(flsll((long long)-1), 64); end:; }