JSBool facFrame(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { uint32_t test,test2; diaElemReadOnlyText align("*****","Value:"); diaElemReadOnlyText txt("blah blah","Value:"); diaElemUInteger bt(&test,"Entry1",0,10); diaElemUInteger bt2(&test2,"Entry2",0,10); diaElemFrame frm("Frame1"); frm.swallow(&txt); frm.swallow(&bt); frm.swallow(&bt2); diaElem *elems[]={&align,&frm }; if(diaFactoryRun("Test frame",2,elems)) { *rval = BOOLEAN_TO_JSVAL(1); }else *rval = BOOLEAN_TO_JSVAL(0); return JS_TRUE; }
JSBool facTab(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { uint32_t test,test2; diaElemReadOnlyText txt("blah blah","Value:"); diaElemUInteger bt(&test,"Entry",0,10); diaElemUInteger bt2(&test2,"Entry",0,10); diaElem *elems1[]={&txt }; diaElem *elems2[]={&bt,&bt2 }; diaElemTabs tab1("T1",1,(diaElem **)elems1); diaElemTabs tab2("T2",2,(diaElem **)elems2); diaElemTabs *tabs[2]={&tab1,&tab2}; if(diaFactoryRunTabs("Test FileRead",2,tabs)) { *rval = BOOLEAN_TO_JSVAL(1); }else *rval = BOOLEAN_TO_JSVAL(0); return JS_TRUE; }
static void test_homo_copy_ctor () { rw_info (0, __FILE__, __LINE__, "copy constructor (homogenous tuples)"); std::tuple<> et1, et2 (et1); _RWSTD_UNUSED (et2); const int ci = std::rand (); const std::tuple<int> it1 (ci); std::tuple<int> it2 (it1); test (__LINE__, it2, ci); const std::tuple<const int>& ct1 = it1; // same as copy ctor std::tuple<const int> ct2 (ct1); test (__LINE__, ct2, ci); int i = ci; const std::tuple<int&> rt1 (i); std::tuple<int&> rt2 (rt1); test (__LINE__, rt2, ci); const std::tuple<std::tuple<int> > nt1 (it1); std::tuple<std::tuple<int> > nt2 (nt1); test (__LINE__, nt2, it1); const std::tuple<long, const char*> pt1 (1234567890L, "string"); std::tuple<long, const char*> pt2 (pt1); test (__LINE__, pt2, 1234567890L, (const char*) "string"); UserDefined ud (ci); const std::tuple<UserDefined> ut1 (ud); UserDefined::reset (); std::tuple<UserDefined> ut2 (ut1); ++UserDefined::expect.copy_ctor; test (__LINE__, ut2, ud); const std::tuple<bool, char, int, double, void*, UserDefined> bt1 (true, 'a', ci, 3.14159, (void* const) &i, ud); ++UserDefined::expect.move_ctor; // moved ud to bt1 std::tuple<bool, char, int, double, void*, UserDefined> bt2 (bt1); ++UserDefined::expect.copy_ctor; // copied to bt2 test (__LINE__, bt2, true, 'a', ci, 3.14159, (void* const) &i, ud); }
JSBool facToggle(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { uint32_t tog=0; uint32_t test=0; diaElemToggle blend(&tog,QT_TR_NOOP("Toggle")); diaElemUInteger bt(&test,"Entry",0,10); diaElemUInteger bt2(&test,"Entry",0,10); diaElem *elems[]={&blend,&bt,&bt2 }; blend.link(1,&bt); blend.link(0,&bt2); if(diaFactoryRun("Test Toggle",3,elems)) { *rval = BOOLEAN_TO_JSVAL(1); printf("Value : %u\n",tog); }else *rval = BOOLEAN_TO_JSVAL(0); return JS_TRUE; }
static void test_homo_move_ctor () { rw_info (0, __FILE__, __LINE__, "move constructor (homogenous tuples)"); std::tuple<> et (std::tuple<> ()); _RWSTD_UNUSED (et); const int ci = std::rand (); std::tuple<int> it1 (ci); std::tuple<int> it2 (std::move (it1)); test (__LINE__, it2, ci); std::tuple<const int> ct1 (ci); std::tuple<const int> ct2 = std::move (ct1); test (__LINE__, ct2, ci); std::tuple<std::tuple<int> > nt1 (it1); std::tuple<std::tuple<int> > nt2 = std::move (nt1); test (__LINE__, nt2, it1); std::tuple<long, const char*> pt1 (1234567890L, "string"); std::tuple<long, const char*> pt2 (std::move (pt1)); test (__LINE__, pt2, 1234567890L, (const char*) "string"); const UserDefined ud (ci); std::tuple<UserDefined> ut1 (ud); UserDefined::reset (); std::tuple<UserDefined> ut2 (std::move (ut1)); ++UserDefined::expect.move_ctor; test (__LINE__, ut2, ud); std::tuple<bool, char, int, double, void*, UserDefined> bt1 (true, 'a', ci, 3.14159, (void*) &ci, ud); ++UserDefined::expect.copy_ctor; std::tuple<bool, char, int, double, void*, UserDefined> bt2 (std::move (bt1)); ++UserDefined::expect.move_ctor; test (__LINE__, bt2, true, 'a', ci, 3.14159, (void*) &ci, ud); }
static void test_lt () { rw_info (0, __FILE__, __LINE__, "operator<"); std::tuple<> nt1, nt2; TEST (!(nt1 < nt1)); TEST (!(nt1 < nt2)); std::tuple<int> it1 (1), it2 (2); TEST (!(it1 < it1)); TEST (it1 < it2); UserDefined ud1 (1), ud2 (2); std::tuple<UserDefined> ut1 (ud1), ut2 (ud2); TEST (!(ut1 < ut1)); TEST (ut1 < ut2); std::tuple<long, const char*> pt1 (1234L, "string"); TEST (!(pt1 < pt1)); std::tuple<long, const char*> pt2 (1235L, "string"); TEST (pt1 < pt2); std::tuple<long, const char*> pt3 (1234L, "strings"); TEST (pt1 < pt3); std::tuple<bool, char, int, double, void*, UserDefined> bt1 (true, 'a', 255, 3.14159, &nt1, ud1), bt2 (true, 'a', 256, 3.14159, &nt1, ud1), bt3 (true, 'a', 255, 3.14159, &nt1, ud2); rw_assert (!(bt1 < bt1), __FILE__, __LINE__, "bt1 < bt1, got true, expected false"); rw_assert (bt1 < bt2, __FILE__, __LINE__, "bt1 < bt2, got false, expected true"); rw_assert (bt1 < bt3, __FILE__, __LINE__, "bt1 < bt3, got false, expected true"); }
static void test_eq () { rw_info (0, __FILE__, __LINE__, "operator=="); std::tuple<> nt1, nt2; // special case rw_assert (nt1 == nt1, __FILE__, __LINE__, "nt1 == nt1, got false, expected true"); #undef TEST #define TEST(expr) \ rw_assert (expr, __FILE__, __LINE__, #expr \ "; got %b, expected %b", !(expr), expr) TEST (nt1 == nt2); std::tuple<int> it1 (1), it2 (1), it3 (2); TEST (it1 == it1); TEST (it1 == it2); TEST (!(it1 == it3)); UserDefined ud1 (1), ud2 (2); std::tuple<UserDefined> ut1 (ud1), ut2 (ud1), ut3 (ud2); TEST (ut1 == ut1); TEST (ut1 == ut2); TEST (!(ut1 == ut3)); std::tuple<bool, char, int, double, void*, UserDefined> bt1 (true, 'a', 255, 3.14159, &nt1, ud1), bt2 (true, 'a', 255, 3.14159, &nt1, ud1), bt3 (true, 'a', 256, 3.14159, &nt1, ud1); TEST (bt1 == bt1); TEST (bt1 == bt2); TEST (!(bt1 == bt3)); }
QT_END_NAMESPACE void tst_QButtonGroup::arrowKeyNavigation() { if (!qt_tab_all_widgets()) QSKIP("This test requires full keyboard control to be enabled."); QDialog dlg(0); QHBoxLayout layout(&dlg); QGroupBox g1("1", &dlg); QHBoxLayout g1layout(&g1); QRadioButton bt1("Radio1", &g1); QPushButton pb("PB", &g1); QLineEdit le(&g1); QRadioButton bt2("Radio2", &g1); g1layout.addWidget(&bt1); g1layout.addWidget(&pb); g1layout.addWidget(&le); g1layout.addWidget(&bt2); // create a mixed button group with radion buttons and push // buttons. Not very useful, but it tests borderline cases wrt // focus handling. QButtonGroup bgrp1(&g1); bgrp1.addButton(&bt1); bgrp1.addButton(&pb); bgrp1.addButton(&bt2); QGroupBox g2("2", &dlg); QVBoxLayout g2layout(&g2); // we don't need a button group here, because radio buttons are // auto exclusive, i.e. they group themselves in he same parent // widget. QRadioButton bt3("Radio3", &g2); QRadioButton bt4("Radio4", &g2); g2layout.addWidget(&bt3); g2layout.addWidget(&bt4); layout.addWidget(&g1); layout.addWidget(&g2); dlg.show(); qApp->setActiveWindow(&dlg); QVERIFY(QTest::qWaitForWindowActive(&dlg)); bt1.setFocus(); QTRY_VERIFY(bt1.hasFocus()); QTest::keyClick(&bt1, Qt::Key_Right); QVERIFY(pb.hasFocus()); QTest::keyClick(&pb, Qt::Key_Right); QVERIFY(bt2.hasFocus()); QTest::keyClick(&bt2, Qt::Key_Right); QVERIFY(bt2.hasFocus()); QTest::keyClick(&bt2, Qt::Key_Left); QVERIFY(pb.hasFocus()); QTest::keyClick(&pb, Qt::Key_Left); QVERIFY(bt1.hasFocus()); QTest::keyClick(&bt1, Qt::Key_Tab); QVERIFY(pb.hasFocus()); QTest::keyClick(&pb, Qt::Key_Tab); QVERIFY(le.hasFocus()); QCOMPARE(le.selectedText(), le.text()); QTest::keyClick(&le, Qt::Key_Tab); QVERIFY(bt2.hasFocus()); QTest::keyClick(&bt2, Qt::Key_Tab); QVERIFY(bt3.hasFocus()); QTest::keyClick(&bt3, Qt::Key_Down); QVERIFY(bt4.hasFocus()); QTest::keyClick(&bt4, Qt::Key_Down); QVERIFY(bt4.hasFocus()); QTest::keyClick(&bt4, Qt::Key_Up); QVERIFY(bt3.hasFocus()); QTest::keyClick(&bt3, Qt::Key_Up); QVERIFY(bt3.hasFocus()); }
int main(int , char**) { std::cout << "Starting hard_work, ready?"; std::cin.ignore(); std::thread my_thread(hard_work); my_thread.join(); std::cout << "Starting background_task, ready?"; std::cin.ignore(); background_task bt; bt(); std::thread my_thread2(bt); //std::thread my_thread2({background_task()}); my_thread2.join(); std::cout << "Starting lambda, ready?"; std::cin.ignore(); std::thread my_thread3( []() { hard_work(); more_hard_work_after_hard_work(); }); my_thread3.join(); std::cout << "ready to crash?"; std::cin.ignore(); { std::thread my_thread( []() { hard_work(); more_hard_work_after_hard_work(); }); my_thread.detach(); } { std::cout << "ready to pass arguments?" << std::endl; std::cin.ignore(); int a = 42; std::thread my_thread(foo, a, "soy un thread!"); std::string str = "soy otro thread"; std::thread my_thread2([](int a1, const std::string& a2) { std::cout << "t2: a1=" << a1 << " a2=" << a2 << std::endl; }, a, str); std::thread my_thread2_capture([&]() { std::cout << "t2 capturing: a1=" << a << " a2=" << str << std::endl; }); background_task_with_args bt1; std::thread my_thread3(bt1,a, "casi el final..."); background_task_with_args_in_ctor bt2(a, "el final del todo"); std::thread my_thread4(bt2); my_thread.join(); my_thread2.join(); my_thread2_capture.join(); my_thread3.join(); my_thread4.join(); } { //std::cout << "ready to pass arguments (oops)?" << std::endl; //std::cin.ignore(); //ooops(1000); //std::cin.ignore(); } { std::unique_ptr<big_object> bo(new big_object); bo->load("machodedatos.raw"); //std::thread process_thread(process_big_object, std::move(bo)); //process_thread.join(); } { std::thread r_thread = return_thread(); join_thread(std::move(r_thread)); } { std::cout << "ready to pass arguments with ScopedThread?" << std::endl; std::cin.ignore(); int a = 42; ScopedThread my_thread(std::thread(foo, a, "soy un thread!")); std::string str = "soy otro thread"; ScopedThread my_thread2(std::thread([](int a1, const std::string& a2) { std::cout << "t2: a1=" << a1 << " a2=" << a2 << std::endl; }, a, str)); ScopedThread my_thread3(std::thread([&]() { std::cout << "t2 capturing: a1=" << a << " a2=" << str << std::endl; })); background_task_with_args bt1; ScopedThread my_thread4(std::thread(bt1,a, "casi el final...")); background_task_with_args_in_ctor bt2(a, "el final del todo"); ScopedThread my_thread5((std::thread(bt2))); } { std::cout << "ready to count cpus?" << std::endl; std::cin.ignore(); std::cout << "num of cpus:" << std::thread::hardware_concurrency() << std::endl; } { std::cout << "ready to check ids?" << std::endl; std::cin.ignore(); std::cout << "main thread id=" << std::this_thread::get_id() << std::endl; std::thread t(check_id); std::thread::id id = t.get_id(); t.join(); std::cout << "thread id=" << id << std::endl; } { std::cout << "ready to fill and find in a list?" << std::endl; std::cin.ignore(); auto producer_function = [](unsigned int numelements) { for(unsigned int i=0;i<numelements;i++) { add_to_list(i); std::this_thread::sleep_for(std::chrono::milliseconds(1)); } }; ScopedThread thread_producer1(std::thread(producer_function,100)); ScopedThread thread_producer2(std::thread(producer_function,100)); auto finder_function = [](unsigned int value_to_find) { auto attempts = 0u; bool found = false; while(!found && attempts < 100) { found = contains_in_list(value_to_find); attempts++; std::this_thread::sleep_for(std::chrono::milliseconds(10)); } if(found) std::cout << std::this_thread::get_id() << ": Found! after " << attempts << " attempts" << std::endl; else std::cout << std::this_thread::get_id() << ": not found! :(" << std::endl; }; ScopedThread thread_finder1(std::thread(finder_function,88)); ScopedThread thread_finder2(std::thread(finder_function,101)); } { std::cout << "ready to crush a stack?" << std::endl; std::cin.ignore(); std::stack<int> s; s.push(42); if(!s.empty()) { int const value = s.top(); s.pop(); foo(value, "do_something"); } std::atomic<int> producersWorking(0); std::atomic<bool> started(false); ThreadSafeStack<int> ts; auto producer_function = [&started, &producersWorking](ThreadSafeStack<int>& ts, unsigned int numelements) { producersWorking++; started = true; for(unsigned int i=0;i<numelements;i++) { ts.push(i); std::this_thread::sleep_for(std::chrono::milliseconds(1)); } producersWorking--; }; auto consumer_function = [&started, &producersWorking](ThreadSafeStack<int>& ts) { while (!started) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } while(producersWorking > 0) { int value; if (ts.pop(value)) { std::cout << std::this_thread::get_id() << ":popped value=" << value << std::endl; std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } std::cout << std::this_thread::get_id() << ":stack is empty" << std::endl; }; ScopedThread thread_producer1(std::thread(producer_function,std::ref(ts),100)); ScopedThread thread_producer2(std::thread(producer_function,std::ref(ts),100)); ScopedThread thread_producer3(std::thread(producer_function, std::ref(ts), 100)); ScopedThread thread_producer4(std::thread(producer_function, std::ref(ts), 100)); ScopedThread thread_consumer1(std::thread(consumer_function,std::ref(ts))); ScopedThread thread_consumer2(std::thread(consumer_function,std::ref(ts))); ScopedThread thread_consumer3(std::thread(consumer_function, std::ref(ts))); } return EXIT_SUCCESS; }