From 9e1dada14b059a9edf2cd6ce0986fa4365457a9f Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Fri, 18 Sep 2020 22:15:36 -0400 Subject: [PATCH] GUACAMOLE-221: Add CUnit tests for guac_strdup() --- src/libguac/tests/Makefile.am | 1 + src/libguac/tests/string/strdup.c | 49 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/libguac/tests/string/strdup.c diff --git a/src/libguac/tests/Makefile.am b/src/libguac/tests/Makefile.am index 6fd3798f..7ee55948 100644 --- a/src/libguac/tests/Makefile.am +++ b/src/libguac/tests/Makefile.am @@ -43,6 +43,7 @@ test_libguac_SOURCES = \ protocol/guac_protocol_version.c \ socket/fd_send_instruction.c \ socket/nested_send_instruction.c \ + string/strdup.c \ string/strlcat.c \ string/strlcpy.c \ string/strljoin.c \ diff --git a/src/libguac/tests/string/strdup.c b/src/libguac/tests/string/strdup.c new file mode 100644 index 00000000..0b1e76b3 --- /dev/null +++ b/src/libguac/tests/string/strdup.c @@ -0,0 +1,49 @@ +/* + * 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 +#include + +/** + * Source test string for copying. + */ +const char* source_string = "Mashing avocados."; + +/** + * A NULL string variable for copying to insure that NULL is copied properly. + */ +const char* null_string = NULL; + +/** + * Verify guac_strdup() behavior when the string is both NULL and not NULL. + */ +void test_string__strdup() { + + /* Copy the strings. */ + char* dest_string = guac_strdup(source_string); + char* null_copy = guac_strdup(null_string); + + /* Run the tests. */ + CU_ASSERT_STRING_EQUAL(dest_string, "Mashing avocados."); + CU_ASSERT_PTR_NULL(null_copy); + +} \ No newline at end of file