void VerifyMaxDump(Backtrace* backtrace) {
  ASSERT_EQ(backtrace->NumFrames(), static_cast<size_t>(MAX_BACKTRACE_FRAMES));
  // Verify that the last frame is our recursive call.
  ASSERT_EQ(backtrace->GetFrame(MAX_BACKTRACE_FRAMES-1)->func_name,
            "test_recursive_call");
}
TEST_F(get_clipboard_string_test, returns_correctly) {
  auto window = (GLFWwindow*)3;
  ASSERT_EQ(m_result, call(window));
}
Beispiel #3
0
static void test_dotdot(const struct dirent *de) {
  ASSERT_EQ(DT_DIR, de->d_type);
  ASSERT_STREQ("..", de->d_name);
}
Beispiel #4
0
TEST(fizzbuzz, shouldReturnBuzzFor5) {
	string actual = fizzbuzz(5);

    ASSERT_EQ("Buzz", actual);
}
Beispiel #5
0
TEST(fizzbuzz, shouldReturn1For1) {
	string actual = fizzbuzz(1);

    ASSERT_EQ("1", actual);
}
Beispiel #6
0
TEST(CompOption,Color)
{

    CompOption::Value value(testColor);

    unsigned short * color = value.c();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor[i], color[i]);

    color = value.get<unsigned short*>();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor[i], color[i]);

    value.set(testColor2);

    color = value.c();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor2[i], color[i]);

    color = value.get<unsigned short*>();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor2[i], color[i]);

    CompOption::Value v;

    v.set (testColor);

    color = v.c();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor[i], color[i]);

    color = v.get<unsigned short*>();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor[i], color[i]);

    v.set(testColor2);

    color = v.c();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor2[i], color[i]);

    color = v.get<unsigned short*>();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor2[i], color[i]);

    v.set (static_cast <short unsigned int *> (testColor));

    color = v.c();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor[i], color[i]);

    color = v.get<unsigned short*>();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor[i], color[i]);

    v.set(testColor2);

    color = v.c();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor2[i], color[i]);

    color = v.get<unsigned short*>();
    ASSERT_NE((void*)0, color);
    for (int i = 0; i != 4; ++i) ASSERT_EQ(testColor2[i], color[i]);
}
Beispiel #7
0
void test_main() {
  VadInstT* self = malloc(sizeof(VadInstT));
  static const int16_t kReference[kNumValidFrameLengths] = { 48, 11, 11 };
  static const int16_t kFeatures[kNumValidFrameLengths * kNumChannels] = {
      1213, 759, 587, 462, 434, 272,
      1479, 1385, 1291, 1200, 1103, 1099,
      1732, 1692, 1681, 1629, 1436, 1436
  };
  static const int16_t kOffsetVector[kNumChannels] = {
      368, 368, 272, 176, 176, 176 };
  int16_t features[kNumChannels];

  // Construct a speech signal that will trigger the VAD in all modes. It is
  // known that (i * i) will wrap around, but that doesn't matter in this case.
  int16_t speech[kMaxFrameLength];
  for (size_t i = 0; i < kMaxFrameLength; ++i) {
    speech[i] = i * i;
  }

  int frame_length_index = 0;
  ASSERT_EQ(0, WebRtcVad_InitCore(self));
  for (size_t j = 0; j < kFrameLengthsSize; ++j) {
    if (ValidRatesAndFrameLengths(8000, kFrameLengths[j])) {
      EXPECT_EQ(kReference[frame_length_index],
                WebRtcVad_CalculateFeatures(self, speech, kFrameLengths[j],
                                            features));
      for (int k = 0; k < kNumChannels; ++k) {
        EXPECT_EQ(kFeatures[k + frame_length_index * kNumChannels],
                  features[k]);
      }
      frame_length_index++;
    }
  }
  EXPECT_EQ(kNumValidFrameLengths, frame_length_index);

  // Verify that all zeros in gives kOffsetVector out.
  memset(speech, 0, sizeof(speech));
  ASSERT_EQ(0, WebRtcVad_InitCore(self));
  for (size_t j = 0; j < kFrameLengthsSize; ++j) {
    if (ValidRatesAndFrameLengths(8000, kFrameLengths[j])) {
      EXPECT_EQ(0, WebRtcVad_CalculateFeatures(self, speech, kFrameLengths[j],
                                               features));
      for (int k = 0; k < kNumChannels; ++k) {
        EXPECT_EQ(kOffsetVector[k], features[k]);
      }
    }
  }

  // Verify that all ones in gives kOffsetVector out. Any other constant input
  // will have a small impact in the sub bands.
  for (size_t i = 0; i < kMaxFrameLength; ++i) {
    speech[i] = 1;
  }
  for (size_t j = 0; j < kFrameLengthsSize; ++j) {
    if (ValidRatesAndFrameLengths(8000, kFrameLengths[j])) {
      ASSERT_EQ(0, WebRtcVad_InitCore(self));
      EXPECT_EQ(0, WebRtcVad_CalculateFeatures(self, speech, kFrameLengths[j],
                                               features));
      for (int k = 0; k < kNumChannels; ++k) {
        EXPECT_EQ(kOffsetVector[k], features[k]);
      }
    }
  }

  free(self);
}
Beispiel #8
0
TEST(Dict, Compress) {

	const char* dictStr = "quickfoxdogjumps";

	DictFlex dict;
	dict.setDict( (const uint8_t*) dictStr, strlen(dictStr) );

	const char* toEncode = "The quick brown fox jumps over the lazy dog123";

	DictEncStream stream(1024*1024);
	DictEncoder enc(&dict);

	enc.append( (const uint8_t*) toEncode, strlen(toEncode), stream);

	dumpHex(std::cout, stream.data, stream.getNumBytes());

	// check
	ASSERT_EQ(42, stream.getNumBytes());
	ASSERT_EQ(0xFF, stream.data[4]);
	ASSERT_EQ(0x00, stream.data[5]);
	ASSERT_EQ(0x05, stream.data[6]);

	ASSERT_EQ(0xFF, stream.data[14]);
	ASSERT_EQ(0x00, stream.data[15]);
	ASSERT_EQ(0x53, stream.data[16]);		// (offset 5) * 16 + (length 3)

	ASSERT_EQ(0xFF, stream.data[18]);
	ASSERT_EQ(0x00, stream.data[19]);
	ASSERT_EQ(0xB5, stream.data[20]);		// (offset 11) * 16 + (length 5)

	ASSERT_EQ(0xFF, stream.data[36]);
	ASSERT_EQ(0x00, stream.data[37]);
	ASSERT_EQ(0x83, stream.data[38]);		// (offset 8) * 16 + (length 3)



}
static int compress_and_expand_and_check(uint8_t *input, uint32_t input_size, int log_lvl) {
    heatshrink_encoder_reset(&hse);
    heatshrink_decoder_reset(&hsd);
    size_t comp_sz = input_size + (input_size/2) + 4;
    size_t decomp_sz = input_size + (input_size/2) + 4;
    uint8_t *comp = malloc(comp_sz);
    uint8_t *decomp = malloc(decomp_sz);
    if (comp == NULL) FAILm("malloc fail");
    if (decomp == NULL) FAILm("malloc fail");
    memset(comp, 0, comp_sz);
    memset(decomp, 0, decomp_sz);

    uint16_t count = 0;

    if (log_lvl > 1) {
        printf("\n^^ COMPRESSING\n");
        dump_buf("input", input, input_size);
    }

    uint32_t sunk = 0;
    uint32_t polled = 0;
    while (sunk < input_size) {
        ASSERT(heatshrink_encoder_sink(&hse, &input[sunk], input_size - sunk, &count) >= 0);
        sunk += count;
        if (log_lvl > 1) printf("^^ sunk %d\n", count);
        if (sunk == input_size) {
            ASSERT_EQ(HSER_FINISH_MORE, heatshrink_encoder_finish(&hse));
        }

        HSE_poll_res pres;
        do {                    /* "turn the crank" */
            pres = heatshrink_encoder_poll(&hse, &comp[polled], comp_sz - polled, &count);
            ASSERT(pres >= 0);
            polled += count;
            if (log_lvl > 1) printf("^^ polled %d\n", count);
        } while (pres == HSER_POLL_MORE);
        ASSERT_EQ(HSER_POLL_EMPTY, pres);
        if (polled >= comp_sz) FAILm("compression should never expand that much");
        if (sunk == input_size) {
            ASSERT_EQ(HSER_FINISH_DONE, heatshrink_encoder_finish(&hse));
        }
    }
    if (log_lvl > 0) printf("in: %u compressed: %u ", input_size, polled);
    uint32_t compressed_size = polled;
    sunk = 0;
    polled = 0;
    
    if (log_lvl > 1) {
        printf("\n^^ DECOMPRESSING\n");
        dump_buf("comp", comp, compressed_size);
    }
    while (sunk < compressed_size) {
        ASSERT(heatshrink_decoder_sink(&hsd, &comp[sunk], compressed_size - sunk, &count) >= 0);
        sunk += count;
        if (log_lvl > 1) printf("^^ sunk %d\n", count);
        if (sunk == compressed_size) {
            ASSERT_EQ(HSDR_FINISH_MORE, heatshrink_decoder_finish(&hsd));
        }

        HSD_poll_res pres;
        do {
            pres = heatshrink_decoder_poll(&hsd, &decomp[polled],
                decomp_sz - polled, &count);
            ASSERT(pres >= 0);
            polled += count;
            if (log_lvl > 1) printf("^^ polled %d\n", count);
        } while (pres == HSDR_POLL_MORE);
        ASSERT_EQ(HSDR_POLL_EMPTY, pres);
        if (sunk == compressed_size) {
            HSD_finish_res fres = heatshrink_decoder_finish(&hsd);
            ASSERT_EQ(HSDR_FINISH_DONE, fres);
        }

        if (polled > input_size) {
            FAILm("Decompressed data is larger than original input");
        }
    }
    if (log_lvl > 0) printf("decompressed: %u\n", polled);
    if (polled != input_size) {
        FAILm("Decompressed length does not match original input length");
    }

    if (log_lvl > 1) dump_buf("decomp", decomp, polled);
    for (int i=0; i<input_size; i++) {
        if (input[i] != decomp[i]) {
            printf("*** mismatch at %d\n", i);
            if (0) {
                for (int j=0; j<=/*i*/ input_size; j++) {
                    printf("in[%d] == 0x%02x ('%c') => out[%d] == 0x%02x ('%c')\n",
                        j, input[j], isprint(input[j]) ? input[j] : '.',
                        j, decomp[j], isprint(decomp[j]) ? decomp[j] : '.');
                }
            }
        }
        ASSERT_EQ(input[i], decomp[i]);
    }
    free(comp);
    free(decomp);
    PASS();
}
/**
 * Tests whether it is possible to use multiple agents.
 */
TEST_F(AlicaMultiAgent, runMultiAgentPlan)
{
	sc->setHostname("nase");
	cace = Cace::getEmulated(sc->getHostname(), sc->getOwnRobotID());
	cace->safeStepMode = true;
	ae = new alica::AlicaEngine();
	ae->setIAlicaClock(new alicaCaceProxy::AlicaCaceClock(cace));
	ae->setCommunicator(new alicaCaceProxy::AlicaCaceCommunication(ae, cace));
	ASSERT_TRUE(ae->init(bc, cc, uc, crc, "RolesetTA", "MultiAgentTestMaster", ".", true))
			<< "Unable to initialise the Alica Engine!";

	sc->setHostname("hairy");
	cace2 = Cace::getEmulated(sc->getHostname(), sc->getOwnRobotID());
	cace2->safeStepMode = true;
	ae2 = new alica::AlicaEngine();
	ae2->setIAlicaClock(new alicaCaceProxy::AlicaCaceClock(cace2));
	ae2->setCommunicator(new alicaCaceProxy::AlicaCaceCommunication(ae2, cace2));
	ASSERT_TRUE(ae2->init(bc, cc, uc, crc, "RolesetTA", "MultiAgentTestMaster", ".", true))
			<< "Unable to initialise the Alica Engine!";

	ae->start();
	ae2->start();

	for (int i = 0; i < 20; i++)
	{
		ae->stepNotify();
		chrono::milliseconds duration(33);
		this_thread::sleep_for(duration);
		ae2->stepNotify();
		this_thread::sleep_for(duration);

//		if (i > 24)
//		{
//			if (ae->getPlanBase()->getDeepestNode() != nullptr)
//				cout << "AE: " << ae->getPlanBase()->getDeepestNode()->toString() << endl;
//			if (ae2->getPlanBase()->getDeepestNode() != nullptr)
//				cout << "AE2: " << ae2->getPlanBase()->getDeepestNode()->toString() << endl;
//			cout << "-------------------------" << endl;
//		}

		if (i < 10)
		{
			ASSERT_EQ(ae->getPlanBase()->getRootNode()->getActiveState()->getId(), 1413200842974);
			ASSERT_EQ(ae2->getPlanBase()->getRootNode()->getActiveState()->getId(), 1413200842974);
		}
		if (i == 10)
		{
			cout << "1--------- Initial State passed ---------" << endl;
			alicaTests::TestWorldModel::getOne()->setTransitionCondition1413201227586(true);
			alicaTests::TestWorldModel::getTwo()->setTransitionCondition1413201227586(true);
		}
		if (i > 11 && i < 15)
		{
			ASSERT_EQ(ae->getPlanBase()->getRootNode()->getActiveState()->getId(), 1413201213955);
			ASSERT_EQ(ae2->getPlanBase()->getRootNode()->getActiveState()->getId(), 1413201213955);
			ASSERT_EQ((*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getPlan()->getName(),
						string("MultiAgentTestPlan"));
			ASSERT_EQ((*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getPlan()->getName(),
						string("MultiAgentTestPlan"));
		}
		if (i == 15)
		{
			for (auto iter : *ae->getBehaviourPool()->getAvailableBehaviours())
			{
				if (iter.second->getName() == "Attack")
				{
					ASSERT_GT(((alicaTests::Attack* )&*iter.second)->callCounter, 5);
					if (((alicaTests::Attack*)&*iter.second)->callCounter > 3)
					{
						alicaTests::TestWorldModel::getOne()->setTransitionCondition1413201052549(true);
						alicaTests::TestWorldModel::getTwo()->setTransitionCondition1413201052549(true);
						alicaTests::TestWorldModel::getOne()->setTransitionCondition1413201370590(true);
						alicaTests::TestWorldModel::getTwo()->setTransitionCondition1413201370590(true);
					}
				}
			}
			cout << "2--------- Engagement to cooperative plan passed ---------" << endl;
		}
		if (i == 16)
		{
			ASSERT_TRUE(
					(*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413201030936
					|| (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413201030936)
					<< endl << (*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId()
					<< " " << (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId()
					<< endl;

			ASSERT_TRUE(
					(*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413807264574
					|| (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413807264574)
					<< endl << (*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId()
					<< " " << (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId()
					<< endl;
			alicaTests::TestWorldModel::getOne()->setTransitionCondition1413201227586(false);
			alicaTests::TestWorldModel::getTwo()->setTransitionCondition1413201227586(false);
			cout << "3--------- Passed transitions in subplan passed ---------" << endl;
		}
		if (i >= 17 && i <= 18)
		{
			ASSERT_TRUE(
					(*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413201030936
					|| (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413201030936)
					<< "AE State: "
					<< (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId()
					<< " AE2 State: "
					<< (*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() << endl;
			ASSERT_TRUE(
					(*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413807264574
					|| (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() == 1413807264574)
					<< "AE State: "
					<< (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() << " "
					<< (*ae->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->toString() << endl
					<< " AE2 State: "
					<< (*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->getId() << " "
					<< (*ae2->getPlanBase()->getRootNode()->getChildren()->begin())->getActiveState()->toString() << endl;
			if(i==18) {
			cout << "4--------- Stayed in these state although previous transitions are not true anymore ---------"
					<< endl;
				alicaTests::TestWorldModel::getOne()->setTransitionCondition1413201389955(true);
				alicaTests::TestWorldModel::getTwo()->setTransitionCondition1413201389955(true);
			}
		}
		if (i == 19)
		{
			ASSERT_TRUE(
					ae2->getPlanBase()->getRootNode()->getActiveState()->getId() == 1413201380359
					&& ae->getPlanBase()->getRootNode()->getActiveState()->getId() == 1413201380359)
					<< " AE State: "
					<< ae->getPlanBase()->getRootNode()->getActiveState()->getId()
					<< " AE2 State: "
					<< ae2->getPlanBase()->getRootNode()->getActiveState()->getId() << endl;
		}
	}
}
Beispiel #11
0
TEST_F(LayouterOpsTest, load_layout_replace) {
  std::string data = loadFromFile("test/json/load_layout_replace.json");
  const auto& e = executeAndWait(data);
  ASSERT_EQ(e->partitionCount(), 3u);
  ASSERT_EQ(3u, StorageManager::getInstance()->getTable("revenue")->partitionCount());
}
TEST(RtTest, TalkerFunction){
    RosTalker rt;
    ASSERT_EQ(3, rt.add(1,2));
}
TEST(NumberCmpTest, ShouldFail){
    ASSERT_EQ(INT_MAX, add(INT_MAX, 1));
}
// a dummy test calling gtest's assert_srteq
// this test is not related with any ros nodeHandle
TEST(NumberCmpTest, ShouldPass){
    ASSERT_EQ(3, add(1,2));
}
Beispiel #15
0
TEST(stdlib, realpath__ENOENT) {
  errno = 0;
  char* p = realpath("/this/directory/path/almost/certainly/does/not/exist", NULL);
  ASSERT_TRUE(p == NULL);
  ASSERT_EQ(ENOENT, errno);
}
Beispiel #16
0
static void TestBug57421_main() {
  pthread_t t;
  ASSERT_EQ(0, pthread_create(&t, NULL, TestBug57421_child, reinterpret_cast<void*>(pthread_self())));
  pthread_exit(NULL);
}
TEST(ReachabilitySphere, fitCylinder_2)
{
    Capability cylinder1(CYLINDER_2, 90.0, 90.0, 20.0);
    
    ReachabilitySphere sphere = createReachabilitySphereFromCapability(cylinder1, 200);
    
    // convert phi and theta to coordinates
    double phiInRad = 90.0 * M_PI / 180.0;
    double thetaInRad = 90.0 * M_PI / 180.0;

    Vector axis;
    axis.x = sin(thetaInRad) * cos(phiInRad);
    axis.y = sin(thetaInRad) * sin(phiInRad);
    axis.z = cos(thetaInRad);
    
    std::pair<double, double> angleAndSFE = sphere.fitCylinder_2(axis);
    ASSERT_TRUE(angleAndSFE.first < 20.01);
    ASSERT_TRUE(angleAndSFE.first > 19.0);
    ASSERT_EQ(angleAndSFE.second, 0.0);


    Capability cylinder2(CYLINDER_2, 320.0, 35.0, 40.0);
    
    sphere = createReachabilitySphereFromCapability(cylinder2, 200);
    
    // convert phi and theta to coordinates
    phiInRad = 320.0 * M_PI / 180.0;
    thetaInRad = 35.0 * M_PI / 180.0;

    axis.x = sin(thetaInRad) * cos(phiInRad);
    axis.y = sin(thetaInRad) * sin(phiInRad);
    axis.z = cos(thetaInRad);
    
    angleAndSFE = sphere.fitCylinder_2(axis);
    ASSERT_TRUE(angleAndSFE.first < 40.01 && angleAndSFE.first > 39.0);
    ASSERT_EQ(angleAndSFE.second, 0.0);


    // check that cylinder_1 is matched too if axis points to opposite direction
    Capability cylinder3(CYLINDER_2, 0.0, 0.0, 20.0);
    
    sphere = createReachabilitySphereFromCapability(cylinder3, 200);
    
    // convert phi and theta to coordinates
    phiInRad = 0.0 * M_PI / 180.0;
    thetaInRad = 180.0 * M_PI / 180.0;

    axis.x = sin(thetaInRad) * cos(phiInRad);
    axis.y = sin(thetaInRad) * sin(phiInRad);
    axis.z = cos(thetaInRad);
    
    angleAndSFE = sphere.fitCylinder_2(axis);
    ASSERT_TRUE(angleAndSFE.first < 20.0);
    ASSERT_EQ(angleAndSFE.second, 0.0);


    // check if SFE grows if axis is not alligned correctly
    Capability cylinder4(CYLINDER_2, 0.0, 0.0, 20.0);
    
    sphere = createReachabilitySphereFromCapability(cylinder4, 200);
    
    // convert phi and theta to coordinates
    phiInRad = 0.0 * M_PI / 180.0;
    thetaInRad = 10.0 * M_PI / 180.0;

    axis.x = sin(thetaInRad) * cos(phiInRad);
    axis.y = sin(thetaInRad) * sin(phiInRad);
    axis.z = cos(thetaInRad);
    
    angleAndSFE = sphere.fitCylinder_2(axis);
    ASSERT_TRUE(angleAndSFE.second > 0.0);
}
Beispiel #18
0
TEST(stdlib, mkstemp) {
  TemporaryFile tf;
  struct stat sb;
  ASSERT_EQ(0, fstat(tf.fd, &sb));
}
Beispiel #19
0
int json_cpp_tests() {
	json::Value e1(json::load_file("test.json"));
	json::Value e2(e1);
	json::Value e3;
	json::Value e4(json::load_string("{\"foo\": true, \"bar\": \"test\"}"));

	ASSERT_TRUE(e1.is_object(), "e1 is not an object");
	ASSERT_TRUE(e2.is_object(), "e2 is not an object");
	ASSERT_TRUE(e3.is_undefined(), "e3 has a defined value");
	ASSERT_TRUE(e4.is_object(), "e4 is not an object");

	ASSERT_EQ(e1.size(), 1, "e1 has too many properties");
	ASSERT_EQ(e2.size(), 1, "e2 has too many properties");
	ASSERT_EQ(e4.size(), 2, "e4 does not have 2 elements");

	ASSERT_TRUE(e1.get("web-app").is_object(), "e1[0].web-app is not an object");
	ASSERT_EQ(e1.get("web-app").get("servlet").at(0).get("servlet-class").as_string(), "org.cofax.cds.CDSServlet", "property has incorrect value");
	ASSERT_EQ(e1["web-app"]["servlet"][0]["servlet-class"].as_string(), "org.cofax.cds.CDSServlet", "property has incorrect value");

	ASSERT_EQ(e4["foo"].as_boolean(), true, "property has incorrect value");

	// verify iterator results (note that they can be returned in any order)
	json::Iterator i(e1.get("web-app"));
	std::set<std::string> iteratorResults;
	for ( int ii = 0; ii < 3; ++ii ) {
		ASSERT_FALSE(i.key().empty(), "iterator returned a null value");
		iteratorResults.insert(i.key());
		i.next();
	}
	ASSERT_FALSE(i.valid(), "iterator has more values than expected");
	ASSERT_EQ(iteratorResults.size(), 3, "iterator did not return enough values");

	json::Value e5(json::Value(12.34));
	ASSERT_TRUE(e5.is_number(), "e5 is not a number after assignment");
	ASSERT_EQ(e5.as_real(), 12.34, "e5 has incorrect value after assignment");

	json::Value e6(json::Value(true));
	ASSERT_TRUE(e6.is_boolean(), "e6 is not a boolean after assignment");
	ASSERT_EQ(e6.as_boolean(), true, "e6 has incorrect value after assignment");

	json::Value e7(json::Value("foobar"));
	ASSERT_TRUE(e7.is_string(), "e7 is not a string after assignment");
	ASSERT_EQ(e7.as_string(), "foobar", "e7 has incorrect value after assignment");

	json::Value e8(json::object());
	ASSERT_TRUE(e8.is_object(), "e8 is not an object after assignment");

	json::Value e9(json::null());
	ASSERT_TRUE(e9.is_null(), "e9 is not null after assignment");

	json::Value e10(json::array());
	ASSERT_TRUE(e10.is_array(), "e10 is not an array after index assignment");

	e10.set_at(0, json::Value("foobar"));
	ASSERT_EQ(e10.size(), 1, "e10 has incorrect number of elements after assignment");
	ASSERT_EQ(e10[0].as_string(), "foobar", "e10[0] has incorrect value after assignment");

	e10.set_at(1, json::Value("foobar"));
	ASSERT_TRUE(e10.is_array(), "e10 is not an array after index assignment");
	ASSERT_EQ(e10.size(), 2, "e10 has incorrect number of elements after assignment");
	ASSERT_EQ(e10[1].as_string(), "foobar", "e10[0] has incorrect value after assignment");

	e10.set_at(0, json::Value("barfoo"));
	ASSERT_TRUE(e10.is_array(), "e10 is not an array after index assignment");
	ASSERT_EQ(e10.size(), 2, "e10 has incorrect number of elements after assignment");
	ASSERT_EQ(e10[0].as_string(), "barfoo", "e10[0] has incorrect value after assignment");

	e10.set_at(100, json::null());
	ASSERT_TRUE(e10.is_array(), "e10 is not an array after index assignment");
	ASSERT_EQ(e10.size(), 2, "e10 has incorrect number of elements after assignment");

	e10.insert_at(1, json::Value("new"));
	ASSERT_EQ(e10.size(), 3, "e10 has incorrect size after insert");
	ASSERT_EQ(e10[1].as_string(), "new", "e10[1] has incorrect value after insert");
	ASSERT_EQ(e10[2].as_string(), "foobar", "e10[2] has incorrect value after insert");

	e10.del_at(0);
	ASSERT_EQ(e10.size(), 2, "e10 has incorrect size after delete");
	ASSERT_EQ(e10[1].as_string(), "foobar", "e10[1] has incorrect value after delete");

	e10.clear();
	ASSERT_EQ(e10.size(), 0, "e10 has incorrect number of elements after clear");

	json::Value e11(json::object());
	ASSERT_TRUE(e11.is_object(), "e11 is not an object after property assignment");

	e11.set_key("foo", json::Value("test"));
	ASSERT_EQ(e11.size(), 1, "e11 has incorrect number of properties after assignment");
	ASSERT_EQ(e11["foo"].as_string(), "test", "e11.foo has incorrect value after assignment");

	e11.set_key("foo", json::Value("again"));
	ASSERT_TRUE(e11.is_object(), "e11 is not an object after property assignment");
	ASSERT_EQ(e11.size(), 1, "e11 has incorrect number of properties after assignment");
	ASSERT_EQ(e11["foo"].as_string(), "again", "e11.foo has incorrect value after assignment");

	e11.set_key("bar", json::Value("test"));
	ASSERT_TRUE(e11.is_object(), "e11 is not an object after property assignment");
	ASSERT_EQ(e11.size(), 2, "e11 has incorrect number of properties after assignment");
	ASSERT_EQ(e11["bar"].as_string(), "test", "e11.foo has incorrect value after assignment");

	e11.clear();
	ASSERT_EQ(e11.size(), 0, "e11 has incorrect number of properties after clear");

	json::Value e12(json::object());
	e12.set_key("foo", json::Value("test"));
	e12.set_key("bar", json::Value(3));
	char* out_cstr = e12.save_string(JSON_COMPACT);
	std::string out(out_cstr);
	free(out_cstr);
	ASSERT_EQ(out, "{\"bar\":3,\"foo\":\"test\"}", "object did not serialize as expected");

	std::istringstream instr(out);
	instr >> e12;
	ASSERT_TRUE(e12.is_object(), "e12 is not an object after stream read");
	ASSERT_EQ(e12.size(), 2, "e12 has wrong size after stream read");
	ASSERT_EQ(e12.get("bar").as_integer(), 3, "e12.bar has incorrect value after stream read");
	ASSERT_EQ(e12.get("foo").as_string(), "test", "ee12.test has incorrect value after stream read");

	std::ostringstream outstr;
	outstr << e12;
	ASSERT_EQ(instr.str(), "{\"bar\":3,\"foo\":\"test\"}", "object did not serialize as expected");

	const json::Value e13(e12);
	ASSERT_EQ(e13["bar"].as_integer(), 3, "e13.bar has incorrect value after copy");

	json::Value e14(json::object());
	ASSERT_TRUE(e14.is_object(), "e14 is not an object after construction");
	e14.set_key("foo", json::object());
	ASSERT_TRUE(e14["foo"].is_object(), "e14.foo is not an object after assignment");
	e14["foo"]["bar"] = json::Value(42);
	ASSERT_EQ(e14["foo"]["bar"].as_integer(), 42, "e14.foo.bar has incorrect value after assignment");

	json::Value e15(json::array());
	ASSERT_TRUE(e15.is_array(), "e15 is not an array after construction");
	e15.set_at(0, json::Value(42));
	ASSERT_EQ(e15[0].as_integer(), 42, "e15[0] has incorrect value after assignment");
	e15[0] = json::Value("foo");
	ASSERT_EQ(e15[0].as_string(), "foo", "e15[0] has incorrecy value after assignment");
	return 0;
}
Beispiel #20
0
TEST(stdlib, mkstemp64) {
  GenericTemporaryFile<mkstemp64> tf;
  struct stat64 sb;
  ASSERT_EQ(0, fstat64(tf.fd, &sb));
  ASSERT_EQ(O_LARGEFILE, fcntl(tf.fd, F_GETFL) & O_LARGEFILE);
}
TEST_F(ResourcePoolTest, get_release) {
    ib_resource_t *ib_r;
    resource_t *r;

    ASSERT_EQ(IB_OK, ib_resource_acquire(m_rp, &ib_r));

    r = reinterpret_cast<resource_t *>(ib_resource_get(ib_r));
    ASSERT_TRUE(r);
    ASSERT_EQ(1U, ib_resource_use_get(ib_r));
    ASSERT_EQ(1, r->preuse);
    ASSERT_EQ(0, r->use);
    ASSERT_EQ(0, r->postuse);
    ASSERT_EQ(0, r->destroy);
    ++(r->use);

    ASSERT_EQ(IB_OK, ib_resource_release(ib_r));
    ASSERT_EQ(1, r->preuse);
    ASSERT_EQ(1, r->use);
    ASSERT_EQ(1, r->postuse);
    ASSERT_EQ(0, r->destroy);

    ASSERT_EQ(IB_OK, ib_resource_acquire(m_rp, &ib_r));
    ASSERT_EQ(2U, ib_resource_use_get(ib_r));
    ASSERT_EQ(IB_OK, ib_resource_release(ib_r));
    ASSERT_EQ(2, r->preuse);
    ASSERT_EQ(2, r->postuse);
    ASSERT_EQ(0, r->destroy);

    ASSERT_EQ(IB_OK, ib_resource_acquire(m_rp, &ib_r));
    ASSERT_EQ(3U, ib_resource_use_get(ib_r));
    ASSERT_EQ(IB_OK, ib_resource_release(ib_r));
    ASSERT_EQ(3, r->preuse);
    ASSERT_EQ(3, r->postuse);
    ASSERT_EQ(0, r->destroy);

    ASSERT_EQ(IB_OK, ib_resource_acquire(m_rp, &ib_r));
    ASSERT_EQ(4U, ib_resource_use_get(ib_r));
    ASSERT_EQ(IB_OK, ib_resource_release(ib_r));
    ASSERT_EQ(4, r->preuse);
    ASSERT_EQ(4, r->postuse);
    ASSERT_EQ(0, r->destroy);

    /* FIXME - destroy after 5. */

    ASSERT_EQ(IB_OK, ib_resource_acquire(m_rp, &ib_r));
    ASSERT_EQ(5U, ib_resource_use_get(ib_r));
    ASSERT_EQ(IB_OK, ib_resource_release(ib_r));
    ASSERT_EQ(0U, ib_resource_use_get(ib_r));
    ASSERT_EQ(5, r->preuse);
    ASSERT_EQ(5, r->postuse);
    ASSERT_EQ(1, r->destroy);

    /* Get an return a resource. This should be no and NOT change r. */
    ASSERT_EQ(IB_OK, ib_resource_acquire(m_rp, &ib_r));
    ASSERT_EQ(IB_OK, ib_resource_release(ib_r));
    ASSERT_EQ(1U, ib_resource_use_get(ib_r));
    ASSERT_EQ(5, r->preuse);
    ASSERT_EQ(5, r->postuse);
    ASSERT_EQ(1, r->destroy);

    /* Get the new r and check it. */
    r = reinterpret_cast<resource_t *>(ib_resource_get(ib_r));
    ASSERT_EQ(1, r->preuse);
    ASSERT_EQ(0, r->use);
    ASSERT_EQ(1, r->postuse);
    ASSERT_EQ(0, r->destroy);
}
Beispiel #22
0
static void quick_exit_1(void) {
  ASSERT_EQ(quick_exit_status, 0);
  quick_exit_status = 1;
}
Beispiel #23
0
TEST(fizzbuzz, shouldReturnFizzbuzzFor15) {
	string actual = fizzbuzz(15);

    ASSERT_EQ("FizzBuzz", actual);
}
Beispiel #24
0
static void quick_exit_2(void) {
  ASSERT_EQ(quick_exit_status, 1);
}
TEST_F(get_clipboard_string_test, has_correct_params) {
  auto window = (GLFWwindow*)4;
  call(window);
  auto first_invocation = s_stub.function_calls().front();
  ASSERT_EQ(first_invocation.param("window"), t_arg(window));
}
Beispiel #26
0
TEST(stdlib, realpath__NULL_filename) {
  errno = 0;
  char* p = realpath(NULL, NULL);
  ASSERT_TRUE(p == NULL);
  ASSERT_EQ(EINVAL, errno);
}
TEST (PoolDictTreeTest, Extending) {
    Buffer input;
    BufferCharWriter writer(input);
    writer.put("ab abcd abde");
    //          ^  ^    ^
    //          0  3    8

    PoolDictTree t(input);
    Node const* root = t.root();
    ASSERT_TRUE(root->is_leaf());
    ASSERT_EQ(Tag(true, 0, 0, 0), root->tag);

    t.extend(0, -int('a') - 1, 1);
    // (0)-a-(1)

    ASSERT_EQ(1, root->child_cnt());
    Edge _a = t.edge(root, 'a');
    ASSERT_EQ("a", _a);
    Node const* a = _a.dst;
    ASSERT_TRUE(a->is_leaf());
    ASSERT_EQ(Tag(true, 1, -int('a') - 1, 1), a->tag);

    t.extend(1, 0, 2);
    // (0)-a-(1)-b-(2)

    ASSERT_EQ(1, root->child_cnt());
    ASSERT_EQ(_a, t.edge(root, 'a'));
    ASSERT_EQ(1, a->child_cnt());
    Edge a_b = t.edge(a, 'b');
    ASSERT_EQ("b", a_b);
    Node const* ab = a_b.dst;
    ASSERT_TRUE(ab->is_leaf());
    ASSERT_EQ(Tag(true, 2, 0, 2), ab->tag);

    t.extend(2, 3, 1);
    // (0)-a-b-(2)-c-(1)

    ASSERT_EQ(1, root->child_cnt());
    Edge _ab = t.edge(root, 'a');
    ASSERT_EQ("ab", _ab);
    ASSERT_EQ(ab, _ab.dst);
    ASSERT_EQ(1, ab->child_cnt());
    Edge ab_c = t.edge(ab, 'c');
    ASSERT_EQ("c", ab_c);
    Node const* abc = ab_c.dst;
    ASSERT_TRUE(abc->is_leaf());
    ASSERT_EQ(Tag(true, 2, 0, 2), ab->tag);
    ASSERT_EQ(Tag(true, 1, 3, 3), abc->tag);

    t.extend(2, 8, 3);
    // (0)-a-b-(2)-c-(1)
    //          |
    //          d
    //          |
    //         (3)

    ASSERT_EQ(1, root->child_cnt());
    ASSERT_EQ(_ab, t.edge(root, 'a'));
    ASSERT_EQ(2, ab->child_cnt());
    ASSERT_EQ(ab_c, t.edge(ab, 'c'));
    ASSERT_TRUE(abc->is_leaf());
    Edge ab_d = t.edge(ab, 'd');
    ASSERT_EQ("d", ab_d);
    Node const* abd = ab_d.dst;
    ASSERT_TRUE(abd->is_leaf());
    ASSERT_EQ(Tag(true, 2, 0, 2), ab->tag);
    ASSERT_EQ(Tag(true, 1, 3, 3), abc->tag);
    ASSERT_EQ(Tag(true, 3, 8, 3), abd->tag);

    t.extend(1, 3, 2);
    // (0)-a-b-(*)-c-(1)-d-(2)
    //          |
    //          d
    //          |
    //         (3)

    ASSERT_EQ(1, root->child_cnt());
    ASSERT_EQ(_ab, t.edge(root, 'a'));
    ASSERT_EQ(2, ab->child_cnt());
    ASSERT_EQ(ab_c, t.edge(ab, 'c'));
    ASSERT_EQ(ab_d, t.edge(ab, 'd'));
    ASSERT_TRUE(abd->is_leaf());
    ASSERT_EQ(1, abc->child_cnt());
    Edge abc_d = t.edge(abc, 'd');
    ASSERT_EQ("d", abc_d);
    Node const* abcd = abc_d.dst;
    ASSERT_TRUE(abcd->is_leaf());
    ASSERT_EQ(Tag(false, 2, 0, 2), ab->tag);
    ASSERT_EQ(Tag(true , 1, 3, 3), abc->tag);
    ASSERT_EQ(Tag(true , 3, 8, 3), abd->tag);
    ASSERT_EQ(Tag(true , 2, 3, 4), abcd->tag);

    t.extend(0, 0, 3);
    // (0)-a-(3)-b-c-(1)-d-(2)

    ASSERT_EQ(1, root->child_cnt());
    _a = t.edge(root, 'a');
    ASSERT_EQ("a", _a);
    a = _a.dst;
    ASSERT_EQ(1, a->child_cnt());
    Edge a_bc = t.edge(a, 'b');
    ASSERT_EQ("bc", a_bc);
    ASSERT_EQ(abc, a_bc.dst);
    ASSERT_EQ(1, abc->child_cnt());
    ASSERT_EQ(abc_d, t.edge(abc, 'd'));
    ASSERT_TRUE(abcd->is_leaf());
    ASSERT_EQ(Tag(true, 3, 0, 1), a->tag);
    ASSERT_EQ(Tag(true, 1, 3, 3), abc->tag);
    ASSERT_EQ(Tag(true, 2, 3, 4), abcd->tag);
}
Beispiel #28
0
TEST(stdlib, realpath__empty_filename) {
  errno = 0;
  char* p = realpath("", NULL);
  ASSERT_TRUE(p == NULL);
  ASSERT_EQ(ENOENT, errno);
}
Beispiel #29
0
 TEST(Sum3Closest, simple) {
     vector<int> a{2, 7, 11, 15};
     Solution* s = new Solution();
     ASSERT_EQ(20, s->threeSumClosest(a, 3));
 }
TEST_F(TesteFila, UltimaPosicao) {
	fila.inclui(0);
	fila.inclui(1);
	fila.inclui(2);
	ASSERT_EQ(2, fila.getUltimo());
}