diff --git a/src/libguac/tests/Makefile.am b/src/libguac/tests/Makefile.am index 4ab3269f..6fd3798f 100644 --- a/src/libguac/tests/Makefile.am +++ b/src/libguac/tests/Makefile.am @@ -40,6 +40,7 @@ test_libguac_SOURCES = \ parser/read.c \ pool/next_free.c \ protocol/base64_decode.c \ + protocol/guac_protocol_version.c \ socket/fd_send_instruction.c \ socket/nested_send_instruction.c \ string/strlcat.c \ diff --git a/src/libguac/tests/protocol/guac_protocol_version.c b/src/libguac/tests/protocol/guac_protocol_version.c new file mode 100644 index 00000000..782b0aa4 --- /dev/null +++ b/src/libguac/tests/protocol/guac_protocol_version.c @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include +#include +#include + +/** + * Test which verifies that conversion of the guac_protocol_version enum to + * string values succeeds and produces the expected results. + */ +void test_guac_protocol__version_to_string() { + + guac_protocol_version version_a = GUAC_PROTOCOL_VERSION_1_3_0; + guac_protocol_version version_b = GUAC_PROTOCOL_VERSION_1_0_0; + guac_protocol_version version_c = GUAC_PROTOCOL_VERSION_UNKNOWN; + + CU_ASSERT_STRING_EQUAL_FATAL(guac_protocol_version_to_string(version_a), "VERSION_1_3_0"); + CU_ASSERT_STRING_EQUAL_FATAL(guac_protocol_version_to_string(version_b), "VERSION_1_0_0"); + CU_ASSERT_PTR_NULL_FATAL(guac_protocol_version_to_string(version_c)); + +} + +/** + * Test which verifies that the version of String representations of Guacamole + * protocol versions are successfully converted into their matching + * guac_protocol_version enum values, and that versions that do not match + * any version get the correct unknown value. + */ +void test_guac_protocol__string_to_version() { + + char* str_version_a = "VERSION_1_3_0"; + char* str_version_b = "VERSION_1_1_0"; + char* str_version_c = "AVACADO"; + char* str_version_d = "VERSION_31_4_1"; + + CU_ASSERT_EQUAL_FATAL(guac_protocol_string_to_version(str_version_a), GUAC_PROTOCOL_VERSION_1_3_0); + CU_ASSERT_EQUAL_FATAL(guac_protocol_string_to_version(str_version_b), GUAC_PROTOCOL_VERSION_1_1_0); + CU_ASSERT_EQUAL_FATAL(guac_protocol_string_to_version(str_version_c), GUAC_PROTOCOL_VERSION_UNKNOWN); + CU_ASSERT_EQUAL_FATAL(guac_protocol_string_to_version(str_version_d), GUAC_PROTOCOL_VERSION_UNKNOWN); + +} + +/** + * Test which verifies that the comparisons between guac_protocol_version enum + * values produces the expected results. + */ +void test_gauc_protocol__version_comparison() { + + CU_ASSERT_TRUE_FATAL(GUAC_PROTOCOL_VERSION_1_3_0 > GUAC_PROTOCOL_VERSION_1_0_0); + CU_ASSERT_TRUE_FATAL(GUAC_PROTOCOL_VERSION_UNKNOWN < GUAC_PROTOCOL_VERSION_1_1_0); + +} \ No newline at end of file