mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 07:38:10 +00:00
Tests: Convert remaining LibC tests to LibTest
Convert them to using outln instead of printf at the same time.
This commit is contained in:
parent
1d253880e6
commit
b3e3e4d45d
9 changed files with 135 additions and 178 deletions
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Ali Mohammad Pur <mpfard@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Types.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct TestCase {
|
||||
const u8* haystack;
|
||||
size_t haystack_length;
|
||||
const u8* needle;
|
||||
size_t needle_length;
|
||||
ssize_t matching_offset { -1 };
|
||||
};
|
||||
|
||||
const static TestCase g_test_cases[] = {
|
||||
{ (const u8*) {}, 0u, (const u8*) {}, 0u, 0 },
|
||||
{ (const u8[]) { 1, 2, 3 }, 3u, (const u8[]) { 1, 2, 3 }, 3u, 0 },
|
||||
{ (const u8[]) { 1, 2, 4 }, 3u, (const u8[]) { 1, 2, 3 }, 3u, -1 },
|
||||
{ (const u8*)"abcdef", 6u, (const u8[]) {}, 0u, 0 },
|
||||
{ (const u8*)"abcdef", 6u, (const u8*)"de", 2u, 3 },
|
||||
{ (const u8[]) { 0, 1, 2, 5, 2, 5 }, 6u, (const u8[]) { 1 }, 1u, 1 },
|
||||
{ (const u8[]) { 0, 1, 2, 5, 2, 5 }, 6u, (const u8[]) { 1, 2 }, 2u, 1 },
|
||||
{ (const u8[]) { 0, 1, 1, 2 }, 4u, (const u8[]) { 1, 5 }, 2u, -1 },
|
||||
{ (const u8[64]) { 0 }, 64u, (const u8[33]) { 0 }, 33u, 0 },
|
||||
{ (const u8[64]) { 0, 1, 1, 2 }, 64u, (const u8[33]) { 1, 1 }, 2u, 1 },
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
bool failed = false;
|
||||
size_t i = 0;
|
||||
for (const auto& test_case : g_test_cases) {
|
||||
auto expected = test_case.matching_offset >= 0 ? test_case.haystack + test_case.matching_offset : nullptr;
|
||||
auto result = memmem(test_case.haystack, test_case.haystack_length, test_case.needle, test_case.needle_length);
|
||||
if (result != expected) {
|
||||
failed = true;
|
||||
fprintf(stderr, "Test %zu FAILED! expected %p, got %p\n", i, expected, result);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
printf(failed ? "FAIL\n" : "PASS\n");
|
||||
return failed ? 1 : 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue