コード例 #1
0
ファイル: factorytest.cpp プロジェクト: xulifei23/gSOAP
int main(int argc, char **argv)
{   if (argc > 1)
        factory = argv[1];			// use factory from command line arg by default
    std::cout << "Connecting to factory " << factory << std::endl;
    Adder adder;				// create unique new remote adder object
    Counter counter1((char*)"myCounter");	// new counter object "myCounter" (created if not exists)
    Counter counter2((char*)"myCounter");	// lookup and use counter "myCounter" (this is an alias to counter1!)
    adder.set(2.0);
    counter1.set(adder.get());
    adder.add(3.0);
    counter1.inc();
    std::cout << "Adder=" << adder.get() << std::endl;
    std::cout << "Counter=" << counter2.get() << std::endl;		// counter2 is an alias for counter1 so this prints the value of counter1
    std::cout << "Sleep for 90 seconds to test factory server purging objects:" << std::endl;
    // counter is periodically incremented which keeps it alive
    sleep(30);
    counter1.inc();
    std::cout << "Counter=" << counter2.get() << std::endl;
    sleep(30);
    counter1.inc();
    std::cout << "Counter=" << counter2.get() << std::endl;
    sleep(30);
    counter1.inc();
    std::cout << "Counter=" << counter2.get() << std::endl;
    // after 90 secs, the adder should be gone
    std::cout << "Adder is no longer available:" << std::endl;
    adder.add(3.0);
    std::cout << "Adder status = " << adder.status << std::endl;
    return 0;
}
//checks that the reduce function is correctly adding the results of two tasks
TEST(MpiWordCounterTests, CheckReduceIsSummingCorrectly)
{
	//four fours and three threes
	std::vector<std::string> example = { "four", "four", "three", "four", "three", "three", "four" };
	mpi_word_counter counter1("four", example);
	mpi_word_counter counter2("three", example);
	counter1.map(0, example.size()-1);
	counter2.map(0, example.size()-1);

	counter1.reduce(counter2.get_count());
	ASSERT_EQ(7, counter1.get_count()); //4+3
}
コード例 #3
0
int main(){
	int i;
	char* s = "Counter = ";
	for (i = 0; i < 5; i++){
		if (i % 2){
		printf("Iteração %d\n",i);
			counter1();
		}else{
		printf("Iteração %d\n",i);
			counter2();
		}
	}
}
コード例 #4
0
ファイル: time_test.cpp プロジェクト: nfxosp/platform_bionic
TEST(time, timer_create_multiple) {
  Counter counter1(Counter::CountNotifyFunction);
  Counter counter2(Counter::CountNotifyFunction);
  Counter counter3(Counter::CountNotifyFunction);

  ASSERT_EQ(0, counter1.Value());
  ASSERT_EQ(0, counter2.Value());
  ASSERT_EQ(0, counter3.Value());

  counter2.SetTime(0, 500000000, 0, 0);
  sleep(1);

  EXPECT_EQ(0, counter1.Value());
  EXPECT_EQ(1, counter2.Value());
  EXPECT_EQ(0, counter3.Value());
}
コード例 #5
0
ファイル: time_test.cpp プロジェクト: WTree/platform_bionic
TEST(time, timer_create_multiple) {
  Counter counter1(Counter::CountNotifyFunction);
  counter1.Create();
  Counter counter2(Counter::CountNotifyFunction);
  counter2.Create();
  Counter counter3(Counter::CountNotifyFunction);
  counter3.Create();

  ASSERT_EQ(0, counter1.value);
  ASSERT_EQ(0, counter2.value);
  ASSERT_EQ(0, counter3.value);

  SetTime(counter2.timer_id, 0, 1, 0, 0);
  usleep(500000);

  EXPECT_EQ(0, counter1.value);
  EXPECT_EQ(1, counter2.value);
  EXPECT_EQ(0, counter3.value);
}
コード例 #6
0
void PerfResourceCounterTest::testMultiCounter()
{
    NoPayloadCounter::Container container;
    NoPayloadCounter counter1(&container);
    NoPayloadCounter counter2(&container);

    QCOMPARE(counter1.currentTotal(), 0ll);
    QCOMPARE(counter2.currentTotal(), 0ll);

    for (quint64 i = 0; i < 100; i += 10) {
        counter1.request(10);
        counter1.obtain(i + 1);
    }

    QCOMPARE(counter1.currentTotal(), 100ll);
    QCOMPARE(counter2.currentTotal(), 0ll);

    for (quint64 i = 100; i < 200; i += 10) {
        counter2.request(10);
        counter2.obtain(i + 1);
    }

    QCOMPARE(counter1.currentTotal(), 100ll);
    QCOMPARE(counter2.currentTotal(), 100ll);

    for (quint64 i = 0; i < 100; i += 10)
        counter2.release(i + 1);

    QCOMPARE(counter1.currentTotal(), 100ll);
    QCOMPARE(counter2.currentTotal(), 0ll);

    for (quint64 i = 100; i < 200; i += 10)
        counter1.release(i + 1);

    QCOMPARE(counter1.currentTotal(), 0ll);
    QCOMPARE(counter2.currentTotal(), 0ll);
}