aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/testcases
diff options
context:
space:
mode:
Diffstat (limited to 'Source/charon/testcases')
-rw-r--r--Source/charon/testcases/generator_test.c76
-rw-r--r--Source/charon/testcases/generator_test.h11
-rw-r--r--Source/charon/testcases/parser_test.c69
-rw-r--r--Source/charon/testcases/parser_test.h11
-rw-r--r--Source/charon/testcases/testcases.c8
5 files changed, 173 insertions, 2 deletions
diff --git a/Source/charon/testcases/generator_test.c b/Source/charon/testcases/generator_test.c
index 0ca227694..30fa042fc 100644
--- a/Source/charon/testcases/generator_test.c
+++ b/Source/charon/testcases/generator_test.c
@@ -45,6 +45,7 @@
#include <encoding/payloads/ts_payload.h>
#include <encoding/payloads/delete_payload.h>
#include <encoding/payloads/vendor_id_payload.h>
+#include <encoding/payloads/cp_payload.h>
/*
* Described in Header
@@ -1346,3 +1347,78 @@ void test_generator_with_vendor_id_payload(tester_t *tester)
charon->logger_manager->destroy_logger(charon->logger_manager,logger);
}
+
+/*
+ * Described in header
+ */
+void test_generator_with_cp_payload(tester_t *tester)
+{
+ generator_t *generator;
+ configuration_attribute_t *attribute1, *attribute2;
+ cp_payload_t *configuration;
+ chunk_t data;
+ chunk_t generated_data;
+ logger_t *logger;
+
+ logger = charon->logger_manager->create_logger(charon->logger_manager,TESTER,"CP Payload");
+
+ /* create generator */
+ generator = generator_create();
+ tester->assert_true(tester,(generator != NULL), "generator create check");
+
+ /* create attribute 1 */
+ attribute1 = configuration_attribute_create();
+ char *stringval = "abcd";
+ data.ptr = (void *) stringval;
+ data.len = 4;
+ attribute1->set_value(attribute1,data);
+ attribute1->set_attribute_type(attribute1,3);
+ logger->log(logger,CONTROL,"attribute1 created");
+
+ /* create attribute 2 */
+ attribute2 = configuration_attribute_create();
+ stringval = "efgh";
+ data.ptr = (void *) stringval;
+ data.len = 4;
+ attribute2->set_value(attribute2,data);
+ attribute2->set_attribute_type(attribute2,4);
+ logger->log(logger,CONTROL,"attribute2 created");
+
+ /* create configuration */
+ configuration = cp_payload_create();
+ tester->assert_true(tester,(configuration != NULL), "configuration create check");
+ configuration->add_configuration_attribute(configuration,attribute1);
+ configuration->add_configuration_attribute(configuration,attribute2);
+ configuration->set_config_type(configuration,5); /* hex 5 */
+
+
+ logger->log(logger,CONTROL,"cp payload created");
+
+ generator->generate_payload(generator,(payload_t *)configuration);
+ generator->write_to_chunk(generator,&generated_data);
+ logger->log_chunk(logger,RAW,"generated configuration",&generated_data);
+
+ u_int8_t expected_generation3[] = {
+ /* cp payload header */
+ 0x00,0x00,0x00,0x18,
+ 0x05,0x00,0x00,0x00,
+ /* configuration attribute 1*/
+ 0x00,0x03,0x00,0x04,
+ 0x61,0x62,0x63,0x64,
+ /* configuration attribute 2*/
+ 0x00,0x04,0x00,0x04,
+ 0x65,0x66,0x67,0x68,
+ };
+
+ logger->log_bytes(logger,RAW,"expected configuration",expected_generation3,sizeof(expected_generation3));
+
+ tester->assert_true(tester,(memcmp(expected_generation3,generated_data.ptr,sizeof(expected_generation3)) == 0), "compare generated data");
+
+ allocator_free_chunk(&generated_data);
+ configuration->destroy(configuration);
+ generator->destroy(generator);
+
+
+ charon->logger_manager->destroy_logger(charon->logger_manager,logger);
+}
+
diff --git a/Source/charon/testcases/generator_test.h b/Source/charon/testcases/generator_test.h
index 31876adee..6adb75638 100644
--- a/Source/charon/testcases/generator_test.h
+++ b/Source/charon/testcases/generator_test.h
@@ -161,4 +161,15 @@ void test_generator_with_delete_payload(tester_t *tester);
*/
void test_generator_with_vendor_id_payload(tester_t *tester);
+
+/**
+ * @brief Test function used to test the generator with CP payload.
+ *
+ * @param tester associated tester_t object
+ *
+ * @ingroup testcases
+ */
+void test_generator_with_cp_payload(tester_t *tester);
+
+
#endif /*GENERATOR_TEST_H_*/
diff --git a/Source/charon/testcases/parser_test.c b/Source/charon/testcases/parser_test.c
index af8d786e4..d4aafadd6 100644
--- a/Source/charon/testcases/parser_test.c
+++ b/Source/charon/testcases/parser_test.c
@@ -41,6 +41,7 @@
#include <encoding/payloads/ts_payload.h>
#include <encoding/payloads/delete_payload.h>
#include <encoding/payloads/vendor_id_payload.h>
+#include <encoding/payloads/cp_payload.h>
/*
@@ -855,4 +856,72 @@ void test_parser_with_vendor_id_payload(tester_t *tester)
vendor_id_payload->destroy(vendor_id_payload);
}
+/*
+ * Described in Header
+ */
+void test_parser_with_cp_payload(tester_t *tester)
+{
+ parser_t *parser;
+ cp_payload_t *cp_payload;
+ configuration_attribute_t *attribute;
+ status_t status;
+ chunk_t cp_chunk;
+ iterator_t *iterator;
+
+ /* first test generic parsing functionality */
+
+ u_int8_t cp_bytes[] = {
+ /* cp payload header */
+ 0x00,0x00,0x00,0x18,
+ 0x05,0x00,0x00,0x00,
+ /* configuration attribute 1*/
+ 0x00,0x03,0x00,0x04,
+ 0x61,0x62,0x63,0x64,
+ /* configuration attribute 2*/
+ 0x00,0x04,0x00,0x04,
+ 0x65,0x66,0x67,0x68,
+ };
+
+ cp_chunk.ptr = cp_bytes;
+ cp_chunk.len = sizeof(cp_bytes);
+
+
+ parser = parser_create(cp_chunk);
+ tester->assert_true(tester,(parser != NULL), "parser create check");
+ status = parser->parse_payload(parser, CONFIGURATION, (payload_t**)&cp_payload);
+ tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
+
+ iterator = cp_payload->create_configuration_attribute_iterator(cp_payload,TRUE);
+
+ tester->assert_true(tester,(iterator->has_next(iterator)),"has_next call check");
+
+ iterator->current(iterator,(void **)&attribute);
+
+ tester->assert_true(tester,(attribute->get_attribute_type(attribute) == 3),"get type check");
+ tester->assert_true(tester,(attribute->get_attribute_length(attribute) == 4),"get type check");
+
+ tester->assert_true(tester,(iterator->has_next(iterator)),"has_next call check");
+
+ iterator->current(iterator,(void **)&attribute);
+
+
+ tester->assert_true(tester,(attribute->get_attribute_type(attribute) == 4),"get type check");
+ tester->assert_true(tester,(attribute->get_attribute_length(attribute) == 4),"get type check");
+
+ iterator->current(iterator,(void **)&attribute);
+
+ tester->assert_false(tester,(iterator->has_next(iterator)),"has_next call check");
+
+
+ iterator->destroy(iterator);
+
+ if (status != SUCCESS)
+ {
+ return;
+ }
+
+ cp_payload->destroy(cp_payload);
+ parser->destroy(parser);
+
+}
diff --git a/Source/charon/testcases/parser_test.h b/Source/charon/testcases/parser_test.h
index 33df377e2..1f9a79a3d 100644
--- a/Source/charon/testcases/parser_test.h
+++ b/Source/charon/testcases/parser_test.h
@@ -145,4 +145,15 @@ void test_parser_with_delete_payload(tester_t *tester);
*/
void test_parser_with_vendor_id_payload(tester_t *tester);
+/**
+ * @brief Test function used to test the parser_t functionality when
+ * parsing a CP payload.
+ *
+ * @param tester associated tester_t object
+ *
+ * @ingroup testcases
+ */
+void test_parser_with_cp_payload(tester_t *tester);
+
+
#endif /*PARSER_TEST_H_*/
diff --git a/Source/charon/testcases/testcases.c b/Source/charon/testcases/testcases.c
index 3aad8e42c..7993de9e9 100644
--- a/Source/charon/testcases/testcases.c
+++ b/Source/charon/testcases/testcases.c
@@ -94,6 +94,7 @@ test_t generator_test12 = {test_generator_with_cert_payload,"Generator: CERT Pay
test_t generator_test13 = {test_generator_with_certreq_payload,"Generator: CERTREQ Payload"};
test_t generator_test14 = {test_generator_with_delete_payload,"Generator: DELETE Payload"};
test_t generator_test15 = {test_generator_with_vendor_id_payload,"Generator: VENDOR ID Payload"};
+test_t generator_test16 = {test_generator_with_cp_payload,"Generator: CP Payload"};
test_t parser_test1 = {test_parser_with_header_payload, "Parser: header payload"};
test_t parser_test2 = {test_parser_with_sa_payload, "Parser: sa payload"};
test_t parser_test3 = {test_parser_with_nonce_payload, "Parser: nonce payload"};
@@ -106,6 +107,7 @@ test_t parser_test9 = {test_parser_with_cert_payload, "Parser: CERT payload"};
test_t parser_test10 = {test_parser_with_certreq_payload, "Parser: CERTREQ payload"};
test_t parser_test11 = {test_parser_with_delete_payload, "Parser: DELETE payload"};
test_t parser_test12 = {test_parser_with_vendor_id_payload, "Parser: VENDOR ID payload"};
+test_t parser_test13 = {test_parser_with_cp_payload, "Parser: CP payload"};
test_t packet_test = {test_packet,"Packet"};
test_t diffie_hellman_test = {test_diffie_hellman,"Diffie Hellman"};
test_t sha1_hasher_test = {test_sha1_hasher,"SHA1 hasher"};
@@ -200,6 +202,7 @@ int main()
&parser_test10,
&parser_test11,
&parser_test12,
+ &parser_test13,
&generator_test3,
&generator_test4,
&generator_test5,
@@ -213,6 +216,7 @@ int main()
&generator_test13,
&generator_test14,
&generator_test15,
+ &generator_test16,
&ike_sa_manager_test,
&packet_test,
&diffie_hellman_test,
@@ -238,13 +242,13 @@ int main()
daemon_create();
charon->logger_manager->disable_logger_level(charon->logger_manager,TESTER,FULL);
-// charon->logger_manager->enable_logger_level(charon->logger_manager,TESTER,RAW);
+ //charon->logger_manager->enable_logger_level(charon->logger_manager,TESTER,RAW);
tester_t *tester = tester_create(test_output, FALSE);
tester->perform_tests(tester,all_tests);
-// tester->perform_test(tester,&parser_test12);
+// tester->perform_test(tester,&parser_test13);
tester->destroy(tester);