void test_int_helpers () { std::cout << "\ntest_int_helpers\n"; // ispow2 for (int i = 1; i < (1<<30); i *= 2) { OIIO_CHECK_ASSERT (ispow2(i)); if (i > 1) OIIO_CHECK_ASSERT (! ispow2(i+1)); } OIIO_CHECK_ASSERT (ispow2(int(0))); OIIO_CHECK_ASSERT (! ispow2(-1)); OIIO_CHECK_ASSERT (! ispow2(-2)); // ispow2, try size_t, which is unsigned for (size_t i = 1; i < (1<<30); i *= 2) { OIIO_CHECK_ASSERT (ispow2(i)); if (i > 1) OIIO_CHECK_ASSERT (! ispow2(i+1)); } OIIO_CHECK_ASSERT (ispow2((unsigned int)0)); // pow2roundup OIIO_CHECK_EQUAL (pow2roundup(4), 4); OIIO_CHECK_EQUAL (pow2roundup(5), 8); OIIO_CHECK_EQUAL (pow2roundup(6), 8); OIIO_CHECK_EQUAL (pow2roundup(7), 8); OIIO_CHECK_EQUAL (pow2roundup(8), 8); // pow2rounddown OIIO_CHECK_EQUAL (pow2rounddown(4), 4); OIIO_CHECK_EQUAL (pow2rounddown(5), 4); OIIO_CHECK_EQUAL (pow2rounddown(6), 4); OIIO_CHECK_EQUAL (pow2rounddown(7), 4); OIIO_CHECK_EQUAL (pow2rounddown(8), 8); // round_to_multiple OIIO_CHECK_EQUAL (round_to_multiple(1, 5), 5); OIIO_CHECK_EQUAL (round_to_multiple(2, 5), 5); OIIO_CHECK_EQUAL (round_to_multiple(3, 5), 5); OIIO_CHECK_EQUAL (round_to_multiple(4, 5), 5); OIIO_CHECK_EQUAL (round_to_multiple(5, 5), 5); OIIO_CHECK_EQUAL (round_to_multiple(6, 5), 10); // round_to_multiple_of_pow2 OIIO_CHECK_EQUAL (round_to_multiple_of_pow2(int(1), 4), 4); OIIO_CHECK_EQUAL (round_to_multiple_of_pow2(int(2), 4), 4); OIIO_CHECK_EQUAL (round_to_multiple_of_pow2(int(3), 4), 4); OIIO_CHECK_EQUAL (round_to_multiple_of_pow2(int(4), 4), 4); OIIO_CHECK_EQUAL (round_to_multiple_of_pow2(int(5), 4), 8); // round_to_multiple_of_pow2 OIIO_CHECK_EQUAL (round_to_multiple_of_pow2(size_t(1), size_t(4)), 4); OIIO_CHECK_EQUAL (round_to_multiple_of_pow2(size_t(2), size_t(4)), 4); OIIO_CHECK_EQUAL (round_to_multiple_of_pow2(size_t(3), size_t(4)), 4); OIIO_CHECK_EQUAL (round_to_multiple_of_pow2(size_t(4), size_t(4)), 4); OIIO_CHECK_EQUAL (round_to_multiple_of_pow2(size_t(5), size_t(4)), 8); }
void test_ustring_lock () { #if (BOOST_VERSION >= 103500) std::cout << "hw threads = " << boost::thread::hardware_concurrency() << "\n"; #endif const int numthreads = 16; boost::thread_group threads; for (int i = 0; i < numthreads; ++i) { threads.create_thread (&create_lotso_ustrings); } std::cout << "Created " << threads.size() << " threads\n"; threads.join_all (); std::cout << "\n" << ustring::getstats() << "\n"; OIIO_CHECK_ASSERT (true); // If we make it here without crashing, pass }
void check_transfer(const ImageBuf &in, const float *table, int size) { // skip the first pixel which will be an invalid negative luminance // value, this value is just to test the fwd transfer doesn't create // nan's. float *pixel = ALLOCA(float, CHANNELS); for (int y = 1; y < STEPS; y++) { in.getpixel (0, y, pixel); for (int c = 0; c < CHANNELS; ++c) { if (c == in.spec().alpha_channel || c == in.spec().z_channel) OIIO_CHECK_EQUAL (pixel[c], ALPHA); else OIIO_CHECK_ASSERT (is_equal(pixel[c], table[y])); } } }
void test_parallel_for () { { // 1D test // vector of ints, initialized to zero const int length = 1000; std::vector<int> vals (length, 0); // Increment all the integers via parallel_for parallel_for (0, length, [&](uint64_t i){ vals[i] += 1; }); // Verify that all elements are exactly 1 bool all_one = std::all_of (vals.cbegin(), vals.cend(), [&](int i){ return vals[i] == 1; }); OIIO_CHECK_ASSERT (all_one); } }