Initial import

This commit is contained in:
Justine Tunney
2020-06-15 07:18:57 -07:00
commit c91b3c5006
14915 changed files with 590219 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ This program is free software; you can redistribute it and/or modify │
│ it under the terms of the GNU General Public License as published by │
│ the Free Software Foundation; version 2 of the License. │
│ │
│ This program is distributed in the hope that it will be useful, but │
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
│ General Public License for more details. │
│ │
│ You should have received a copy of the GNU General Public License │
│ along with this program; if not, write to the Free Software │
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
│ 02110-1301 USA │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/bits/bits.h"
#include "libc/conv/conv.h"
#include "libc/testlib/testlib.h"
TEST(basename, test) {
EXPECT_STREQ("", basename(""));
EXPECT_STREQ("hello", basename("hello"));
EXPECT_STREQ("there", basename("hello/there"));
EXPECT_STREQ("yo", basename("hello/there/yo"));
}
TEST(basename, testTrailingSlash_isIgnored) {
/* should be "foo" but basename() doesn't allocate memory */
EXPECT_STREQ("foo/", basename("foo/"));
EXPECT_STREQ("foo//", basename("foo//"));
}
TEST(basename, testOnlySlashes_oneSlashOnlyVasily) {
EXPECT_STREQ("/", basename("///"));
}
TEST(basename, testWindows_isGrantedRespect) {
EXPECT_STREQ("there", basename("hello\\there"));
EXPECT_STREQ("yo", basename("hello\\there\\yo"));
}

View File

@@ -0,0 +1,36 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ This program is free software; you can redistribute it and/or modify │
│ it under the terms of the GNU General Public License as published by │
│ the Free Software Foundation; version 2 of the License. │
│ │
│ This program is distributed in the hope that it will be useful, but │
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
│ General Public License for more details. │
│ │
│ You should have received a copy of the GNU General Public License │
│ along with this program; if not, write to the Free Software │
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
│ 02110-1301 USA │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/bits/bits.h"
#include "libc/conv/conv.h"
#include "libc/limits.h"
#include "libc/testlib/testlib.h"
TEST(llog10, test) {
EXPECT_EQ(0, llog10(1));
EXPECT_EQ(0, llog10(2));
EXPECT_EQ(0, llog10(9));
EXPECT_EQ(1, llog10(10));
EXPECT_EQ(1, llog10(11));
EXPECT_EQ(1, llog10(99));
EXPECT_EQ(2, llog10(100));
EXPECT_EQ(2, llog10(101));
EXPECT_EQ(9, llog10(INT_MAX));
EXPECT_EQ(12, llog10(1000000000000));
}

View File

@@ -0,0 +1,50 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ This program is free software; you can redistribute it and/or modify │
│ it under the terms of the GNU General Public License as published by │
│ the Free Software Foundation; version 2 of the License. │
│ │
│ This program is distributed in the hope that it will be useful, but │
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
│ General Public License for more details. │
│ │
│ You should have received a copy of the GNU General Public License │
│ along with this program; if not, write to the Free Software │
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
│ 02110-1301 USA │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/conv/conv.h"
#include "libc/conv/sizemultiply.h"
#include "libc/limits.h"
#include "libc/testlib/testlib.h"
size_t out;
TEST(sizemultiply, testMultiplication) {
EXPECT_TRUE(sizemultiply(&out, 7, 11));
EXPECT_EQ(7 * 11, out);
EXPECT_TRUE(sizemultiply(&out, 11, 7));
EXPECT_EQ(7 * 11, out);
EXPECT_TRUE(sizemultiply(&out, 0, 11));
EXPECT_EQ(0 * 11, out);
EXPECT_TRUE(sizemultiply(&out, 11, 0));
EXPECT_EQ(0 * 11, out);
}
TEST(sizemultiply, testOverflow_alwaysReturnsSizeMax) {
EXPECT_FALSE(sizemultiply(&out, 7, SIZE_MAX));
EXPECT_EQ(SIZE_MAX, out);
EXPECT_FALSE(sizemultiply(&out, SIZE_MAX, 7));
EXPECT_EQ(SIZE_MAX, out);
}
TEST(sizemultiply, testOverflow_closeButNoCigar) {
EXPECT_TRUE(sizemultiply(&out, SIZE_MAX, 1));
EXPECT_EQ(SIZE_MAX, out);
EXPECT_TRUE(sizemultiply(&out, 1, SIZE_MAX));
EXPECT_EQ(SIZE_MAX, out);
}

View File

@@ -0,0 +1,38 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ This program is free software; you can redistribute it and/or modify │
│ it under the terms of the GNU General Public License as published by │
│ the Free Software Foundation; version 2 of the License. │
│ │
│ This program is distributed in the hope that it will be useful, but │
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
│ General Public License for more details. │
│ │
│ You should have received a copy of the GNU General Public License │
│ along with this program; if not, write to the Free Software │
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
│ 02110-1301 USA │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/bits/bits.h"
#include "libc/conv/conv.h"
#include "libc/testlib/testlib.h"
/* todo(jart): work on this more */
TEST(strtoimax, testZero) { EXPECT_EQ(0, strtoimax("0", NULL, 0)); }
TEST(strtoimax, testDecimal) { EXPECT_EQ(-123, strtoimax("-123", NULL, 0)); }
TEST(strtoimax, testHex) { EXPECT_EQ(-255, strtoimax("-0xff", NULL, 0)); }
TEST(strtoimax, testOctal) { EXPECT_EQ(-123, strtoimax("-0173", NULL, 0)); }
TEST(strtoimax, testLimits) {
EXPECT_EQ(
((uintmax_t)0xffffffffffffffff) << 64 | (uintmax_t)0xffffffffffffffff,
strtoimax("-1", NULL, 0));
EXPECT_EQ(
((uintmax_t)0x7fffffffffffffff) << 64 | (uintmax_t)0xffffffffffffffff,
strtoimax("0x7fffffffffffffffffffffffffffffff", NULL, 0));
}

View File

@@ -0,0 +1,35 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ This program is free software; you can redistribute it and/or modify │
│ it under the terms of the GNU General Public License as published by │
│ the Free Software Foundation; version 2 of the License. │
│ │
│ This program is distributed in the hope that it will be useful, but │
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
│ General Public License for more details. │
│ │
│ You should have received a copy of the GNU General Public License │
│ along with this program; if not, write to the Free Software │
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
│ 02110-1301 USA │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/bits/bits.h"
#include "libc/conv/conv.h"
#include "libc/limits.h"
#include "libc/testlib/testlib.h"
TEST(strtoumax, testZero) { EXPECT_EQ(UINTMAX_MIN, strtoumax("0", NULL, 0)); }
TEST(strtoumax, testDecimal) { EXPECT_EQ(123, strtoumax("123", NULL, 0)); }
TEST(strtoumax, testHex) { EXPECT_EQ(255, strtoumax("0xff", NULL, 0)); }
TEST(strtoumax, testOctal) { EXPECT_EQ(123, strtoumax("0173", NULL, 0)); }
TEST(strtoumax, testMaximum) {
EXPECT_EQ(UINTMAX_MAX,
strtoumax("340282366920938463463374607431768211455", NULL, 0));
EXPECT_EQ(UINTMAX_MAX,
strtoumax("0xffffffffffffffffffffffffffffffff", NULL, 0));
}

57
test/libc/conv/test.mk Normal file
View File

@@ -0,0 +1,57 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
PKGS += TEST_LIBC_CONV
TEST_LIBC_CONV_SRCS := $(wildcard test/libc/conv/*.c)
TEST_LIBC_CONV_SRCS_TEST = $(filter %_test.c,$(TEST_LIBC_CONV_SRCS))
TEST_LIBC_CONV_COMS = $(TEST_LIBC_CONV_OBJS:%.o=%.com)
TEST_LIBC_CONV_OBJS = \
$(TEST_LIBC_CONV_SRCS:%=o/$(MODE)/%.zip.o) \
$(TEST_LIBC_CONV_SRCS:%.c=o/$(MODE)/%.o)
TEST_LIBC_CONV_BINS = \
$(TEST_LIBC_CONV_COMS) \
$(TEST_LIBC_CONV_COMS:%=%.dbg)
TEST_LIBC_CONV_TESTS = \
$(TEST_LIBC_CONV_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
TEST_LIBC_CONV_CHECKS = \
$(TEST_LIBC_CONV_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
TEST_LIBC_CONV_DIRECTDEPS = \
LIBC_CONV \
LIBC_NEXGEN32E \
LIBC_STUBS \
LIBC_TESTLIB
TEST_LIBC_CONV_DEPS := \
$(call uniq,$(foreach x,$(TEST_LIBC_CONV_DIRECTDEPS),$($(x))))
o/$(MODE)/test/libc/conv/conv.pkg: \
$(TEST_LIBC_CONV_OBJS) \
$(foreach x,$(TEST_LIBC_CONV_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/test/libc/conv/%.com.dbg: \
$(TEST_LIBC_CONV_DEPS) \
o/$(MODE)/test/libc/conv/%.o \
o/$(MODE)/test/libc/conv/conv.pkg \
$(LIBC_TESTMAIN) \
$(CRT) \
$(APE)
@$(APELINK)
$(TEST_LIBC_CONV_OBJS): \
$(BUILD_FILES) \
test/libc/conv/test.mk
$(TEST_LIBC_CONV_OBJS): \
DEFAULT_CCFLAGS += \
-fno-builtin
.PHONY: o/$(MODE)/test/libc/conv
o/$(MODE)/test/libc/conv: \
$(TEST_LIBC_CONV_BINS) \
$(TEST_LIBC_CONV_CHECKS)

View File

@@ -0,0 +1,33 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ This program is free software; you can redistribute it and/or modify │
│ it under the terms of the GNU General Public License as published by │
│ the Free Software Foundation; version 2 of the License. │
│ │
│ This program is distributed in the hope that it will be useful, but │
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
│ General Public License for more details. │
│ │
│ You should have received a copy of the GNU General Public License │
│ along with this program; if not, write to the Free Software │
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
│ 02110-1301 USA │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/calls/struct/timeval.h"
#include "libc/conv/conv.h"
#include "libc/nt/struct/filetime.h"
#include "libc/testlib/testlib.h"
#include "libc/time/time.h"
TEST(timevaltofiletime, roundTrip) {
struct timeval tv1, tv2;
tv1.tv_sec = 31337;
tv1.tv_usec = 1337;
filetimetotimeval(&tv2, timevaltofiletime(&tv1));
EXPECT_EQ(31337, tv2.tv_sec);
EXPECT_EQ(1337, tv2.tv_usec);
}