summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Cowgill <jcowgill@debian.org>2023-11-29 20:04:20 +0000
committerJames Cowgill <jcowgill@debian.org>2023-11-29 22:51:07 +0000
commit94ea55e2d4e4ab9dc3627ada23b99f84f669865d (patch)
treec58b0d03eaeee71a68b9304635ca6e952cfe4e21
parent213183b013158c4807a021c1d3a42a9a518a47b4 (diff)
d/tests: Refactor detect.c into a separate file
-rw-r--r--debian/tests/build46
-rw-r--r--debian/tests/detect.c42
2 files changed, 43 insertions, 45 deletions
diff --git a/debian/tests/build b/debian/tests/build
index ade750d..575620e 100644
--- a/debian/tests/build
+++ b/debian/tests/build
@@ -10,6 +10,7 @@ then
exit 1
fi
+cp debian/tests/detect.c "$AUTOPKGTEST_TMP"
cd "$AUTOPKGTEST_TMP"
if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then
@@ -18,51 +19,6 @@ else
CROSS_COMPILE=
fi
-cat <<EOF > detect.c
-#include <stdio.h>
-#include <uchardet.h>
-
-// Runs uchardet on stdin and prints the result to stdout
-
-int main(void)
-{
- uchardet_t handle = uchardet_new();
- if (handle == NULL)
- {
- perror("uchardet_new");
- return 1;
- }
-
- // Read all data into uchardet
- for (;;)
- {
- char buf[4096];
- size_t len = fread(buf, 1, sizeof(buf), stdin);
- if (ferror(stdin))
- {
- perror("fread");
- uchardet_delete(handle);
- return 1;
- }
-
- if (uchardet_handle_data(handle, buf, len) != 0)
- {
- perror("uchardet_handle_data");
- return 1;
- }
-
- if (len < sizeof(buf))
- break;
- }
-
- // Get character set
- uchardet_data_end(handle);
- puts(uchardet_get_charset(handle));
- uchardet_delete(handle);
- return 0;
-}
-EOF
-
# Build program
${CROSS_COMPILE}gcc -Wall -Werror -I/usr/include/uchardet -o detect1 detect.c -luchardet
echo "build1: OK"
diff --git a/debian/tests/detect.c b/debian/tests/detect.c
new file mode 100644
index 0000000..76cfbfa
--- /dev/null
+++ b/debian/tests/detect.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <uchardet.h>
+
+// Runs uchardet on stdin and prints the result to stdout
+
+int main(void)
+{
+ uchardet_t handle = uchardet_new();
+ if (handle == NULL)
+ {
+ perror("uchardet_new");
+ return 1;
+ }
+
+ // Read all data into uchardet
+ for (;;)
+ {
+ char buf[4096];
+ size_t len = fread(buf, 1, sizeof(buf), stdin);
+ if (ferror(stdin))
+ {
+ perror("fread");
+ uchardet_delete(handle);
+ return 1;
+ }
+
+ if (uchardet_handle_data(handle, buf, len) != 0)
+ {
+ perror("uchardet_handle_data");
+ return 1;
+ }
+
+ if (len < sizeof(buf))
+ break;
+ }
+
+ // Get character set
+ uchardet_data_end(handle);
+ puts(uchardet_get_charset(handle));
+ uchardet_delete(handle);
+ return 0;
+}