summaryrefslogtreecommitdiffstats
path: root/triehash/tests/test-enum-include-name-flags
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 18:07:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 18:07:13 +0000
commit636c7dc17286d93d788c741d15fd756aeda066d5 (patch)
treee7ae158cc54f591041a061b9865bcae51854f15c /triehash/tests/test-enum-include-name-flags
parentInitial commit. (diff)
downloadapt-636c7dc17286d93d788c741d15fd756aeda066d5.tar.xz
apt-636c7dc17286d93d788c741d15fd756aeda066d5.zip
Adding upstream version 1.8.2.3.upstream/1.8.2.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-xtriehash/tests/test-enum-include-name-flags129
1 files changed, 129 insertions, 0 deletions
diff --git a/triehash/tests/test-enum-include-name-flags b/triehash/tests/test-enum-include-name-flags
new file mode 100755
index 0000000..33bd97c
--- /dev/null
+++ b/triehash/tests/test-enum-include-name-flags
@@ -0,0 +1,129 @@
+#!/bin/sh
+. $(dirname $(readlink -f $0))/framework.sh
+
+# Need a short word, we really just need to check if the labels work
+WORDS=w
+
+testsuccessequal "\
+#ifndef TRIE_HASH_PerfectHash
+#define TRIE_HASH_PerfectHash
+#include <stddef.h>
+#include <stdint.h>
+#include <foo.h>
+enum PerfectKey {
+ w = 0,
+ Unknown = -1,
+};
+ enum PerfectKey PerfectHash(const char *string, size_t length);
+#endif /* TRIE_HASH_PerfectHash */" triehash --multi-byte=0 -C /dev/null --include="<foo.h>" /dev/stdin
+
+# Check for --enum-class support
+testsuccessequal "\
+#ifndef TRIE_HASH_PerfectHash
+#define TRIE_HASH_PerfectHash
+#include <stddef.h>
+#include <stdint.h>
+enum class PerfectKey {
+ w = 0,
+ Unknown = -1,
+};
+static enum PerfectKey PerfectHash(const char *string, size_t length);
+static enum PerfectKey PerfectHash1(const char *string)
+{
+ switch(string[0]) {
+ case 'w':
+ return PerfectKey::w;
+ }
+ return PerfectKey::Unknown;
+}
+static enum PerfectKey PerfectHash(const char *string, size_t length)
+{
+ switch (length) {
+ case 1:
+ return PerfectHash1(string);
+ default:
+ return PerfectKey::Unknown;
+ }
+}
+#endif /* TRIE_HASH_PerfectHash */" triehash --multi-byte=0 --enum-class /dev/stdin
+
+# Check for --enum-name support
+testsuccessequal "\
+#ifndef TRIE_HASH_PerfectHash
+#define TRIE_HASH_PerfectHash
+#include <stddef.h>
+#include <stdint.h>
+enum Foo {
+ Unknown = -1,
+};
+static enum Foo PerfectHash(const char *string, size_t length);
+static enum Foo PerfectHash(const char *string, size_t length)
+{
+ switch (length) {
+ default:
+ return Unknown;
+ }
+}
+#endif /* TRIE_HASH_PerfectHash */\
+" triehash --multi-byte=0 --enum-name="Foo"
+
+# Check for --enum-class support
+testsuccessequal "\
+#ifndef TRIE_HASH_PerfectHash
+#define TRIE_HASH_PerfectHash
+#include <stddef.h>
+#include <stdint.h>
+enum class Foo::Bar {
+ Unknown = -1,
+};
+static enum Foo::Bar PerfectHash(const char *string, size_t length);
+static enum Foo::Bar PerfectHash(const char *string, size_t length)
+{
+ switch (length) {
+ default:
+ return Foo::Bar::Unknown;
+ }
+}
+#endif /* TRIE_HASH_PerfectHash */\
+" triehash --multi-byte=0 --enum-class --enum-name="Foo::Bar"
+
+# Check for --function-name support
+testsuccessequal "\
+#ifndef TRIE_HASH_NonSense
+#define TRIE_HASH_NonSense
+#include <stddef.h>
+#include <stdint.h>
+enum PerfectKey {
+ Unknown = -1,
+};
+static enum PerfectKey NonSense(const char *string, size_t length);
+static enum PerfectKey NonSense(const char *string, size_t length)
+{
+ switch (length) {
+ default:
+ return Unknown;
+ }
+}
+#endif /* TRIE_HASH_NonSense */\
+" triehash --multi-byte=0 --function-name="NonSense"
+
+# Check for --counter-name support
+testsuccessequal "\
+#ifndef TRIE_HASH_PerfectHash
+#define TRIE_HASH_PerfectHash
+#include <stddef.h>
+#include <stdint.h>
+enum { MyCounter = 0 };
+enum PerfectKey {
+ Unknown = -1,
+};
+static enum PerfectKey PerfectHash(const char *string, size_t length);
+static enum PerfectKey PerfectHash(const char *string, size_t length)
+{
+ switch (length) {
+ default:
+ return Unknown;
+ }
+}
+#endif /* TRIE_HASH_PerfectHash */\
+" triehash --multi-byte=0 --counter-name="MyCounter"