Skip to content

Commit

Permalink
Merge pull request #250 from CIPop/test_simplification2
Browse files Browse the repository at this point in the history
MQTT Test Refactor Part 2
  • Loading branch information
icraggs authored Aug 24, 2023
2 parents a8f0eb5 + 7ddcc02 commit f4f9c8f
Show file tree
Hide file tree
Showing 4 changed files with 444 additions and 0 deletions.
54 changes: 54 additions & 0 deletions MQTTPacket/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@ SET_TESTS_PROPERTIES(
PROPERTIES TIMEOUT 540
)

# test3 - MQTTv3 broker test
ADD_EXECUTABLE(
test3
test3.c
../samples/transport.c
)

# Disabling deprecation warnings:
# warning: ‘ftime’ is deprecated [-Wdeprecated-declarations]
target_compile_options(test3 PRIVATE -Wno-deprecated-declarations)

TARGET_LINK_LIBRARIES(
test3
paho-embed-mqtt3c
)

ADD_TEST(
NAME test3
COMMAND "test3" "--connection" ${MQTT_TEST_BROKER}
)

SET_TESTS_PROPERTIES(
test3
PROPERTIES TIMEOUT 540
)

# test4 - MQTTv5 broker test
ADD_EXECUTABLE(
test4
Expand All @@ -90,3 +116,31 @@ SET_TESTS_PROPERTIES(
test4
PROPERTIES TIMEOUT 540
)

# test5 - MQTTv3 side-by-side with MQTTv5 broker test
ADD_EXECUTABLE(
test5
test5.c
../samples/transport.c
)

# Disabling deprecation warnings:
# warning: ‘ftime’ is deprecated [-Wdeprecated-declarations]
target_compile_options(test5 PRIVATE -Wno-deprecated-declarations)
target_compile_definitions(test5 PRIVATE NOSIGPIPE)

TARGET_LINK_LIBRARIES(
test5
paho-embed-mqtt3c
paho-embed-mqtt5c
)

ADD_TEST(
NAME test5
COMMAND "test5" "--connection" ${MQTT_TEST_BROKER}
)

SET_TESTS_PROPERTIES(
test5
PROPERTIES TIMEOUT 540
)
54 changes: 54 additions & 0 deletions MQTTPacket/test/test3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright (c) 2014, 2023 IBM Corp., Ian Craggs and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Ian Craggs - initial API and implementation and/or initial documentation
* Sergio R. Caprile - clarifications and/or documentation extension
*******************************************************************************/

/***
Test MQTTPacket against a broker.
***/

#include "test_framework.h"
#include "MQTTPacket.h"
#include "transport.h"

#include "test_mqtt3.h"

int main(int argc, char** argv)
{
int rc = 0;
int (*tests[])(struct Options) = {NULL, test_v3};

xml = fopen("TEST-test3.xml", "w");
fprintf(xml, "<testsuite name=\"test1\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1));

getopts(argc, argv);

if (options.test_no == 0)
{ /* run all the tests */
for (options.test_no = 1; options.test_no < ARRAY_SIZE(tests); ++options.test_no)
rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */
}
else
rc = tests[options.test_no](options); /* run just the selected test */

if (rc == 0)
MyLog(LOGA_INFO, "verdict pass");
else
MyLog(LOGA_INFO, "verdict fail");

fprintf(xml, "</testsuite>\n");
fclose(xml);
return rc;
}
53 changes: 53 additions & 0 deletions MQTTPacket/test/test5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2023 Microsoft Corporation. All rights reserved.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
*******************************************************************************/

/***
Side-by-side MQTTv3 and MQTTv5 Tests.
***/

#include "test_framework.h"
#include "MQTTPacket.h"
#include "MQTTV5Packet.h"
#include "transport.h"

#include "test_mqtt3.h"
#include "test_mqtt5.h"

int main(int argc, char** argv)
{
int rc = 0;
int (*tests[])(struct Options) = {NULL, test_v3, test_v5};

xml = fopen("TEST-test5.xml", "w");
fprintf(xml, "<testsuite name=\"test35\" tests=\"%d\">\n", (int)(ARRAY_SIZE(tests) - 1));

getopts(argc, argv);

if (options.test_no == 0)
{ /* run all the tests */
for (options.test_no = 1; options.test_no < ARRAY_SIZE(tests); ++options.test_no)
rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */
}
else
rc = tests[options.test_no](options); /* run just the selected test */

if (rc == 0)
MyLog(LOGA_INFO, "verdict pass");
else
MyLog(LOGA_INFO, "verdict fail");

fprintf(xml, "</testsuite>\n");
fclose(xml);
return rc;
}
Loading

0 comments on commit f4f9c8f

Please sign in to comment.