diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2022-09-02 05:47:02 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2022-09-02 05:47:02 +0000 |
commit | 0dbbf1e0708df85a357d70e2708c0a11aeb5480e (patch) | |
tree | 6656ff8eb8b15a2fc1c02888973caf618388cfd0 /lib/mesa/src/util/tests/string_buffer | |
parent | 5f66494d31f735486b8222ecfa0a0c9046e92543 (diff) |
Merge Mesa 22.1.7
Diffstat (limited to 'lib/mesa/src/util/tests/string_buffer')
-rw-r--r-- | lib/mesa/src/util/tests/string_buffer/meson.build | 30 | ||||
-rw-r--r-- | lib/mesa/src/util/tests/string_buffer/string_buffer_test.cpp | 122 |
2 files changed, 0 insertions, 152 deletions
diff --git a/lib/mesa/src/util/tests/string_buffer/meson.build b/lib/mesa/src/util/tests/string_buffer/meson.build deleted file mode 100644 index 9f42e3550..000000000 --- a/lib/mesa/src/util/tests/string_buffer/meson.build +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright © 2017 Intel Corporation - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -test( - 'string_buffer', - executable( - 'string_buffer_test', - 'string_buffer_test.cpp', - dependencies : [dep_thread, dep_dl, idep_gtest], - include_directories : inc_common, - link_with : [libmesa_util], - ) -) diff --git a/lib/mesa/src/util/tests/string_buffer/string_buffer_test.cpp b/lib/mesa/src/util/tests/string_buffer/string_buffer_test.cpp deleted file mode 100644 index 545f607fa..000000000 --- a/lib/mesa/src/util/tests/string_buffer/string_buffer_test.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright © 2017 Thomas Helland - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <assert.h> -#include <gtest/gtest.h> -#include "util/string_buffer.h" - -/** - * \file string_buffer_test.cpp - * - * Test the string buffer implementation - */ - -#define INITIAL_BUF_SIZE 6 -class string_buffer : public ::testing::Test { -public: - - struct _mesa_string_buffer *buf; - const char *str1; - const char *str2; - const char *str3; - char str4[80]; - char str5[40]; - - virtual void SetUp(); - virtual void TearDown(); -}; - -void -string_buffer::SetUp() -{ - str1 = "test1"; - str2 = "test2"; - str3 = "test1test2"; - buf = _mesa_string_buffer_create(NULL, INITIAL_BUF_SIZE); -} - -void -string_buffer::TearDown() -{ - /* Finally, clean up after us */ - _mesa_string_buffer_destroy(buf); -} - -static uint32_t -space_left_in_buffer(_mesa_string_buffer *buf) -{ - return buf->capacity - buf->length - 1; -} - -TEST_F(string_buffer, string_buffer_tests) -{ - /* The string terminator needs one byte, so there should one "missing" */ - EXPECT_TRUE(space_left_in_buffer(buf) == INITIAL_BUF_SIZE - 1); - - /* Start by appending str1 */ - EXPECT_TRUE(_mesa_string_buffer_append(buf, str1)); - EXPECT_TRUE(space_left_in_buffer(buf) == - INITIAL_BUF_SIZE - strlen(str1) - 1); - EXPECT_TRUE(strcmp(buf->buf, str1) == 0); - - /* Add more, so that the string is resized */ - EXPECT_TRUE(_mesa_string_buffer_append(buf, str2)); - - /* The string should now be equal to str3 */ - EXPECT_TRUE(strcmp(buf->buf, str3) == 0); - - /* Check that the length of the string is reset when clearing */ - _mesa_string_buffer_clear(buf); - EXPECT_TRUE(buf->length == 0); - EXPECT_TRUE(strlen(buf->buf) == 0); - - /* Test a string with some formatting */ - sprintf(str4, "Testing formatting %d, %f", 100, 1.0); - EXPECT_TRUE(_mesa_string_buffer_printf(buf, "Testing formatting %d, %f", 100, 1.0)); - EXPECT_TRUE(strcmp(buf->buf, str4) == 0); - - /* Compile a string with some other formatting */ - sprintf(str5, "Testing formatting %d, %x", 100, 0xDEADBEAF); - - /* Concatenate str5 to str4 */ - strcat(str4, str5); - - /* Now use the formatted append function again */ - EXPECT_TRUE(_mesa_string_buffer_printf(buf, "Testing formatting %d, %x", 100, 0xDEADBEAF)); - - /* The string buffer should now be equal to str4 */ - EXPECT_TRUE(strcmp(buf->buf, str4) == 0); - - _mesa_string_buffer_clear(buf); - - /* Test appending by one char at a time */ - EXPECT_TRUE(_mesa_string_buffer_append_char(buf, 'a')); - EXPECT_TRUE(buf->length == 1); - EXPECT_TRUE(strcmp(buf->buf, "a") == 0); - EXPECT_TRUE(_mesa_string_buffer_append_char(buf, 'a')); - EXPECT_TRUE(strcmp(buf->buf, "aa") == 0); -} |