cscg24-guacamole

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

split.c (1903B)


      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 "common/string.h"
     21
     22#include <CUnit/CUnit.h>
     23#include <guacamole/mem.h>
     24
     25#include <stdlib.h>
     26
     27/**
     28 * Test which verifies that guac_split() splits a string on occurrences of a
     29 * given character.
     30 */
     31void test_string__split() {
     32
     33    /* Split test string */
     34    char** tokens = guac_split("this is a test string", ' ');
     35    CU_ASSERT_PTR_NOT_NULL(tokens);
     36
     37    /* Check resulting tokens */
     38    CU_ASSERT_PTR_NOT_NULL_FATAL(tokens[0]);
     39    CU_ASSERT_STRING_EQUAL("this", tokens[0]);
     40
     41    CU_ASSERT_PTR_NOT_NULL_FATAL(tokens[1]);
     42    CU_ASSERT_STRING_EQUAL("is", tokens[1]);
     43
     44    CU_ASSERT_PTR_NOT_NULL_FATAL(tokens[2]);
     45    CU_ASSERT_STRING_EQUAL("a", tokens[2]);
     46
     47    CU_ASSERT_PTR_NOT_NULL_FATAL(tokens[3]);
     48    CU_ASSERT_STRING_EQUAL("test", tokens[3]);
     49
     50    CU_ASSERT_PTR_NOT_NULL_FATAL(tokens[4]);
     51    CU_ASSERT_STRING_EQUAL("string", tokens[4]);
     52
     53    CU_ASSERT_PTR_NULL(tokens[5]);
     54
     55    /* Clean up */
     56    guac_mem_free(tokens[0]);
     57    guac_mem_free(tokens[1]);
     58    guac_mem_free(tokens[2]);
     59    guac_mem_free(tokens[3]);
     60    guac_mem_free(tokens[4]);
     61    guac_mem_free(tokens);
     62
     63}
     64