summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/meson.build11
-rw-r--r--tests/term_test.c72
-rw-r--r--tests/version_test.c27
3 files changed, 110 insertions, 0 deletions
diff --git a/tests/meson.build b/tests/meson.build
index 82493af..629f6d5 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -118,6 +118,17 @@ if cc.has_link_argument('-Wl,--wrap=realloc') and cc.has_link_argument('-Wl,--wr
suite: 'unit',
)
endif
+
+# The project version comes in as a define, so the header macros cannot
+# drift from meson.build.
+version_test = executable('version-test', 'version_test.c',
+ c_args: test_c_args + ['-DTERM_TEST_PROJECT_VERSION="@0@"'.format(meson.project_version())],
+ dependencies: [term_internal_dep],
+)
+test('version-test', version_test,
+ env: test_env,
+ suite: 'unit',
+)
test('term-cross-test', bash,
args: [files('cross_test.sh'), meson.project_source_root()],
suite: 'portability',
diff --git a/tests/term_test.c b/tests/term_test.c
index 66dbd96..7b531b1 100644
--- a/tests/term_test.c
+++ b/tests/term_test.c
@@ -1440,6 +1440,55 @@ static void test_snapshot_follows_new_terminal(void)
term_snapshot_free(s);
}
+/* The getters take a NULL snapshot and an out-of-range row like a NULL
+ * terminal: they return the empty value. The view keeps its address. */
+static void test_snapshot_null_and_range(void)
+{
+ uint32_t cps[4] = { 0xAAAA, 0xAAAA, 0xAAAA, 0xAAAA };
+ assert(term_snapshot_view(NULL) == NULL);
+ assert(term_snapshot_row(NULL, 0) == NULL);
+ assert(term_snapshot_row_key(NULL, 0) == 0);
+ struct term_span none = term_snapshot_row_selection(NULL, 0);
+ assert(none.begin == 0 && none.end == 0);
+ assert(term_snapshot_cluster(NULL, 'a', cps, 4) == 0);
+ assert(term_snapshot_cluster(NULL, TERM_TEXT_CLUSTER, cps, 4) == 0);
+ assert(cps[0] == 0xAAAA);
+
+ struct term *t = tt_new(4, 2);
+ tt_write(t, "e\xcc\x81", 3);
+ struct term_snapshot *s = term_snapshot_new();
+ assert(term_snapshot_update(s, t));
+
+ const struct term_view *view = term_snapshot_view(s);
+ const uint32_t *palette = view->palette;
+ assert(term_snapshot_update(s, t));
+ assert(term_snapshot_view(s) == view && view->palette == palette);
+
+ assert(term_snapshot_row(s, -1) == NULL);
+ assert(term_snapshot_row(s, 2) == NULL);
+ assert(term_snapshot_row_key(s, -1) == 0);
+ assert(term_snapshot_row_key(s, 2) == 0);
+ struct term_span off = term_snapshot_row_selection(s, 2);
+ assert(off.begin == 0 && off.end == 0);
+
+ /* A cluster cell gives its count with no buffer, and with cap 0 it
+ * writes nothing. */
+ uint32_t text = term_snapshot_row(s, 0)[0].text;
+ assert(text & TERM_TEXT_CLUSTER);
+ assert(term_snapshot_cluster(s, text, NULL, 0) == 2);
+ assert(term_snapshot_cluster(s, text, cps, 0) == 2);
+ assert(cps[0] == 0xAAAA);
+ assert(term_snapshot_cluster(s, text, NULL, 4) == 2);
+ /* A plain code point is one code point, and cap 0 writes nothing. */
+ assert(term_snapshot_cluster(s, 'a', NULL, 0) == 1);
+ assert(term_snapshot_cluster(s, 'a', cps, 0) == 1);
+ assert(cps[0] == 0xAAAA);
+ assert(term_snapshot_cluster(s, 'a', cps, 4) == 1 && cps[0] == 'a');
+
+ term_snapshot_free(s);
+ term_free(t);
+}
+
static void test_string_payloads(void)
{
static const char *prefixes[] = {"\033]0;", "\033]7;file://host/", "\033P"};
@@ -1832,8 +1881,30 @@ static void test_concurrent_feed_and_snapshot(void)
term_free(t);
}
+static void test_reserved_options_must_be_zero(void)
+{
+ struct term_options opt = { .size = { .x = 10, .y = 2 } };
+ struct term *t = term_new(&opt);
+ assert(t != NULL);
+ term_free(t);
+
+ size_t words = sizeof(opt.reserved) / sizeof(opt.reserved[0]);
+ for (size_t i = 0; i < words; i++) {
+ opt.reserved[i] = 1;
+ assert(term_new(&opt) == NULL);
+ opt.reserved[i] = 0;
+ }
+ opt.reserved[words - 1] = 0x80000000u;
+ assert(term_new(&opt) == NULL);
+ opt.reserved[words - 1] = 0;
+ t = term_new(&opt);
+ assert(t != NULL);
+ term_free(t);
+}
+
int main(void)
{
+ test_reserved_options_must_be_zero();
test_concurrent_feed_and_snapshot();
test_grow_past_reservation();
test_skipped_cells_read_blank();
@@ -1859,6 +1930,7 @@ int main(void)
test_alt_shrink_then_flood();
test_alt_erase_scrollback();
test_snapshot_follows_new_terminal();
+ test_snapshot_null_and_range();
test_bulk_rows_survive_edits();
assert(!strcmp(UNICODE_DATA_VERSION, "18.0.0"));
diff --git a/tests/version_test.c b/tests/version_test.c
new file mode 100644
index 0000000..0eb889e
--- /dev/null
+++ b/tests/version_test.c
@@ -0,0 +1,27 @@
+#include "term/term.h"
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+/* The project version from meson.build. The build defines it. */
+#ifndef TERM_TEST_PROJECT_VERSION
+#error "define TERM_TEST_PROJECT_VERSION as the project version, such as \"0.1.0\""
+#endif
+
+int main(void)
+{
+ char text[32];
+ snprintf(text, sizeof(text), "%d.%d.%d",
+ TERM_VERSION_MAJOR, TERM_VERSION_MINOR, TERM_VERSION_PATCH);
+ assert(!strcmp(text, TERM_TEST_PROJECT_VERSION));
+
+ int major, minor, patch;
+ assert(sscanf(TERM_TEST_PROJECT_VERSION, "%d.%d.%d", &major, &minor, &patch) == 3);
+ assert(TERM_VERSION_CODE == TERM_VERSION(major, minor, patch));
+ assert(term_version() == TERM_VERSION_CODE);
+
+ assert(TERM_VERSION(0, 2, 0) > TERM_VERSION(0, 1, 255));
+ assert(TERM_VERSION(1, 0, 0) > TERM_VERSION(0, 255, 255));
+ return 0;
+}