Ejemplo n.º 1
0
TEST_C(DequeTests, DequeZipIterNext)
{
    deque_add(deque, "a");
    deque_add(deque, "b");
    deque_add(deque, "c");
    deque_add(deque, "d");

    Deque *d2;
    deque_new(&d2);

    deque_add(d2, "e");
    deque_add(d2, "f");
    deque_add(d2, "g");

    DequeZipIter zip;
    deque_zip_iter_init(&zip, deque, d2);

    size_t i = 0;

    void *e1, *e2;
    while (deque_zip_iter_next(&zip, &e1, &e2) != CC_ITER_END) {
        if (i == 0) {
          CHECK_EQUAL_C_STRING("a", (char*)e1);
          CHECK_EQUAL_C_STRING("e", (char*)e2);
        }
        if (i == 2) {
          CHECK_EQUAL_C_STRING("c", (char*)e1);
          CHECK_EQUAL_C_STRING("g", (char*)e2);
        }
        i++;
    }
    CHECK_EQUAL_C_INT(3, i);
    deque_destroy(d2);
};
Ejemplo n.º 2
0
TEST_C(DequeTests, DequeZipIterRemove)
{
    deque_add(deque, "a");
    deque_add(deque, "b");
    deque_add(deque, "c");
    deque_add(deque, "d");

    Deque *d2;
    deque_new(&d2);

    deque_add(d2, "e");
    deque_add(d2, "f");
    deque_add(d2, "g");

    DequeZipIter zip;
    deque_zip_iter_init(&zip, deque, d2);

    void *e1, *e2;
    void *r1, *r2;
    while (deque_zip_iter_next(&zip, &e1, &e2) != CC_ITER_END) {
        if (strcmp((char*) e1, "b") == 0)
            deque_zip_iter_remove(&zip, &r1, &r2);
    }
    CHECK_EQUAL_C_STRING("b", (char*)r1);
    CHECK_EQUAL_C_STRING("f", (char*)r2);
    CHECK_EQUAL_C_INT(0, deque_contains(deque, "b"));
    CHECK_EQUAL_C_INT(0, deque_contains(deque, "f"));
    CHECK_EQUAL_C_INT(3, deque_size(deque));
    CHECK_EQUAL_C_INT(2, deque_size(d2));
    deque_destroy(d2);
};
Ejemplo n.º 3
0
TEST(TestHarness_c, checkString)
{
	CHECK_EQUAL_C_STRING("Hello", "Hello");
	fixture->setTestFunction(_failStringMethod);
	fixture->runAllTests();
	fixture->assertPrintContains("expected <Hello>\n	but was  <World>");
	fixture->assertPrintContains("arness_c");
//	fixture->assertPrintContains("TestHarness_cTest.cpp");
}
Ejemplo n.º 4
0
TEST(TestHarness_c, checkString)
{
	CHECK_EQUAL_C_STRING("Hello", "Hello");
	fixture->setTestFunction(_failStringMethod);
	fixture->runAllTests();

	StringEqualFailure failure(UtestShell::getCurrent(), "file", 1, "Hello", "Hello World");
	fixture->assertPrintContains(failure.getMessage());
	fixture->assertPrintContains("arness_c");
	CHECK(!hasDestructorOfTheDestructorCheckedBeenCalled)
}
/* G:5 - Yield, network connected, yield called while in subscribe application callback */
TEST_C(YieldTests, YieldInSubscribeCallback) {
	IoT_Error_t rc = SUCCESS;
	char expectedCallbackString[] = "0xA5A5A3";

	IOT_DEBUG("-->Running Yield Tests - G:5 - Yield, network connected, yield called while in subscribe application callback \n");

	setTLSRxBufferForSuback(subTopic, subTopicLen, QOS1, testPubMsgParams);
	rc = aws_iot_mqtt_subscribe(&iotClient, subTopic, subTopicLen, QOS1,
								iot_tests_unit_yield_test_subscribe_callback_handler, NULL);
	if(SUCCESS == rc) {
		setTLSRxBufferWithMsgOnSubscribedTopic(subTopic, subTopicLen, QOS1, testPubMsgParams, expectedCallbackString);
		rc = aws_iot_mqtt_yield(&iotClient, 1000);
		if(SUCCESS == rc) {
			CHECK_EQUAL_C_STRING(expectedCallbackString, CallbackMsgString);
		}
		CHECK_EQUAL_C_INT(1, isLastTLSTxMessagePuback());
	}

	IOT_DEBUG("-->Success - G:5 - Yield, network connected, yield called while in subscribe application callback \n");
}
Ejemplo n.º 6
0
static void _failStringMethod()
{
	HasTheDestructorBeenCalledChecker checker;
	CHECK_EQUAL_C_STRING("Hello", "Hello World");
}
Ejemplo n.º 7
0
void _failStringMethod()
{
	CHECK_EQUAL_C_STRING("Hello", "World");
}
/* G:12 - Yield, resubscribe to all topics on reconnect */
TEST_C(YieldTests, resubscribeSuccessfulReconnect) {
	IoT_Error_t rc = FAILURE;
	char cPayload[100];
	bool connected = false;
	bool autoReconnectEnabled = false;
	char expectedCallbackString[100];

	IOT_DEBUG("-->Running Yield Tests - G:12 - Yield, resubscribe to all topics on reconnect \n");

	rc = aws_iot_mqtt_autoreconnect_set_status(&iotClient, true);
	CHECK_EQUAL_C_INT(SUCCESS, rc);

	snprintf(CallbackMsgString, 100, "NOT_VISITED");

	testPubMsgParams.qos = QOS1;
	testPubMsgParams.isRetained = 0;
	snprintf(cPayload, 100, "%s : %d ", "hello from SDK", 0);
	testPubMsgParams.payload = (void *) cPayload;
	testPubMsgParams.payloadLen = strlen(cPayload);

	connected = aws_iot_mqtt_is_client_connected(&iotClient);
	CHECK_EQUAL_C_INT(1, connected);

	ResetTLSBuffer();

	/* Subscribe to a topic */
	setTLSRxBufferForSuback(subTopic, subTopicLen, QOS1, testPubMsgParams);
	rc = aws_iot_mqtt_subscribe(&iotClient, subTopic, subTopicLen, QOS0, iot_tests_unit_acr_subscribe_callback_handler,
								NULL);
	CHECK_EQUAL_C_INT(SUCCESS, rc);

	ResetTLSBuffer();

	/* Check subscribe */
	snprintf(expectedCallbackString, 100, "Message for %s", subTopic);
	setTLSRxBufferWithMsgOnSubscribedTopic(subTopic, subTopicLen, QOS1, testPubMsgParams, expectedCallbackString);
	rc = aws_iot_mqtt_yield(&iotClient, 100);
	CHECK_EQUAL_C_INT(SUCCESS, rc);
	CHECK_EQUAL_C_STRING(expectedCallbackString, CallbackMsgString);

	ResetTLSBuffer();

	autoReconnectEnabled = aws_iot_is_autoreconnect_enabled(&iotClient);
	CHECK_EQUAL_C_INT(1, autoReconnectEnabled);

	/* Sleep for half keep alive interval to allow the first ping to be sent out */
	sleep(iotClient.clientData.keepAliveInterval / (uint32_t)2);
	rc = aws_iot_mqtt_yield(&iotClient, 100);
	CHECK_EQUAL_C_INT(SUCCESS, rc);
	CHECK_EQUAL_C_INT(true, isLastTLSTxMessagePingreq());

	/* Let ping request time out and call yield */
	sleep(iotClient.clientData.keepAliveInterval / (uint32_t)2 + 1);
	rc = aws_iot_mqtt_yield(&iotClient, 100);
	CHECK_EQUAL_C_INT(NETWORK_ATTEMPTING_RECONNECT, rc);

	sleep(2); /* Default min reconnect delay is 1 sec */

	ResetTLSBuffer();
	setTLSRxBufferForConnackAndSuback(&connectParams, 0, subTopic, subTopicLen, QOS1);

	rc = aws_iot_mqtt_yield(&iotClient, 100);
	CHECK_EQUAL_C_INT(SUCCESS, rc);

	/* Test if reconnect worked */
	connected = aws_iot_mqtt_is_client_connected(&iotClient);
	CHECK_EQUAL_C_INT(true, connected);

	ResetTLSBuffer();

	/* Check subscribe */
	snprintf(expectedCallbackString, 100, "Message for %s after resub", subTopic);
	setTLSRxBufferWithMsgOnSubscribedTopic(subTopic, subTopicLen, QOS1, testPubMsgParams, expectedCallbackString);
	rc = aws_iot_mqtt_yield(&iotClient, 100);
	CHECK_EQUAL_C_INT(SUCCESS, rc);
	CHECK_EQUAL_C_STRING(expectedCallbackString, CallbackMsgString);
	CHECK_EQUAL_C_INT(true, dcHandlerInvoked);

	IOT_DEBUG("-->Success - G:12 - Yield, resubscribe to all topics on reconnect \n");
}