/* * Little explanation: * 0x00-0x7f ASCII, one byte character * 0x80-0xbf continuation byte, not a valid start byte * 0xc0-0xdf 2-byte character * 0xe0-0xef 3-byte character * 0xf0-0xf7 4-byte character * 0xf8-0xff reserved (illegal at the present time) */ static void utf8_validate_test (OilTest *test) { int i; int n = test->n; uint8_t *ptr = oil_test_get_source_data (test, OIL_ARG_SRC1); int x; int extra_chars = 0; for (i=0;i<n;i++){ if (i >= n-16) { /* if it's close to the end, we'll randomly drop in a bad * byte from either the 0x80-0xbf or 0xf8-0xff segments */ x = oil_rand_u8(); if (x < 16) { x = oil_rand_u8(); if (extra_chars>0) { /* this might not actually be a bad char */ ptr[i] = x; extra_chars--; } else { if (x & 0x80) { ptr[i] = 0x80 | (x&0x3f); } else { ptr[i] = 0xf8 | (x&0x07); } } continue; } } if (extra_chars > 0) { ptr[i] = 0x80 | (oil_rand_u8() & 0x3f); extra_chars--; } else { /* otherwise, we'll do a low probability of a multibyte char */ x = oil_rand_u8() & 0xf; if (x == 0) { ptr[i] = 0xc0 | (oil_rand_u8() & 0x1f); extra_chars = 1; } else if (x == 1) { ptr[i] = 0xe0 | (oil_rand_u8() & 0x0f); extra_chars = 2; } else if (x == 2) { ptr[i] = 0xf0 | (oil_rand_u8() & 0x07); extra_chars = 3; } else { ptr[i] = oil_rand_u8() & 0x7f; } } } }
void encode (SchroBuffer *buffer, int n, int freq) { SchroArith *a; int i; int bit; a = schro_arith_new(); schro_arith_encode_init (a, buffer); for(i=0;i<n;i++){ bit = oil_rand_u8() < freq; schro_arith_encode_bit (a, 0, bit); } schro_arith_flush (a); a->buffer = NULL; schro_arith_free(a); }
void test(void) { int32_t dest[1]; uint8_t src[100]; int i; for(i=0;i<100;i++){ src[i] = oil_rand_u8() & 0x7f; } dest[0] = 0; oil_utf8_validate (dest, src, 100); #if 0 for(i=0;i<100;i++){ printf("%d %d\n",dest[i],src[i]); } #endif printf("%d\n", dest[0]); }
int main (int argc, char *argv[]) { OilFunctionClass *klass; OilFunctionImpl *impl; OilTest *test; int i; int n; int j; int ret; unsigned int cpu_flags; //xmlfile = "stride"; std_log(LOG_FILENAME_LINE, "Test Started testsuite_stride"); if (argc > 1 && strcmp(argv[1],"-v") == 0) { verbose = 1; } oil_init (); cpu_flags = oil_cpu_get_flags (); n = oil_class_get_n_classes (); for (i=0;i<n; i++ ) { klass = oil_class_get_by_index(i); std_log(LOG_FILENAME_LINE,"Class Name %s %d\n",klass->name, i); test = oil_test_new (klass); if (test == NULL) { std_log(LOG_FILENAME_LINE,"class \"%s\" has bad prototype\n", klass->name); assert_failed = fail = 1; continue; } oil_test_set_iterations (test, 1); test->n = 1 + oil_rand_u8(); test->m = 1 + oil_rand_u8(); std_log(LOG_FILENAME_LINE, "ref impl %s",klass->reference_impl->name); oil_test_check_impl (test, klass->reference_impl); //Testing whether an appropriate implementation is suitable or not //Runs the testing procedure described by test on the implementation impl for(j=0;j<OIL_ARG_LAST;j++) { if (test->params[j].is_stride) { test->params[j].value += oil_type_sizeof(test->params[j].type) * (oil_rand_u8()&0xf); } } test->inited = 0; for (impl = klass->first_impl; impl; impl = impl->next) { std_log(LOG_FILENAME_LINE," %s\n", impl->name); if ((impl->flags & OIL_CPU_FLAG_MASK) & ~cpu_flags){ std_log(LOG_FILENAME_LINE, "Not supported"); } else { ret = oil_test_check_impl (test, impl); if (!ret) { assert_failed = fail = 1; oil_test_free (test); std_log(LOG_FILENAME_LINE, "Test Failed"); create_xml(1); return fail; } } } oil_test_free (test); } if(assert_failed) std_log(LOG_FILENAME_LINE,"Test Fail"); else std_log(LOG_FILENAME_LINE,"Test Successful"); create_xml(0); return fail; }