cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

strdup.c (1550B)


      1/*
      2 * Licensed to the Apache Software Foundation (ASF) under one
      3 * or more contributor license agreements.  See the NOTICE file
      4 * distributed with this work for additional information
      5 * regarding copyright ownership.  The ASF licenses this file
      6 * to you under the Apache License, Version 2.0 (the
      7 * "License"); you may not use this file except in compliance
      8 * with the License.  You may obtain a copy of the License at
      9 *
     10 *   http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing,
     13 * software distributed under the License is distributed on an
     14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15 * KIND, either express or implied.  See the License for the
     16 * specific language governing permissions and limitations
     17 * under the License.
     18 */
     19
     20#include <CUnit/CUnit.h>
     21#include <guacamole/mem.h>
     22#include <guacamole/string.h>
     23
     24#include <stdlib.h>
     25#include <string.h>
     26
     27/**
     28 * Source test string for copying.
     29 */
     30const char* source_string = "Mashing avocados.";
     31
     32/**
     33 * A NULL string variable for copying to insure that NULL is copied properly.
     34 */
     35const char* null_string = NULL;
     36
     37/**
     38 * Verify guac_strdup() behavior when the string is both NULL and not NULL.
     39 */
     40void test_string__strdup() {
     41
     42    /* Copy the strings. */
     43    char* dest_string = guac_strdup(source_string);
     44    char* null_copy = guac_strdup(null_string);
     45    
     46    /* Run the tests. */
     47    CU_ASSERT_STRING_EQUAL(dest_string, "Mashing avocados.");
     48    CU_ASSERT_PTR_NULL(null_copy);
     49
     50    guac_mem_free(dest_string);
     51
     52}