aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-10-13 19:07:57 +0200
committerMattias Andrée <maandree@kth.se>2017-10-13 19:07:57 +0200
commit76485979dd99159f032b35a4bf87cb0b8ed4c87d (patch)
treec207ff5fcef5a71a3407b0121bbc19a30d70248f
parentRewrite with style (and relicense) (diff)
downloadadjbacklight-76485979dd99159f032b35a4bf87cb0b8ed4c87d.tar.gz
adjbacklight-76485979dd99159f032b35a4bf87cb0b8ed4c87d.tar.bz2
adjbacklight-76485979dd99159f032b35a4bf87cb0b8ed4c87d.tar.xz
Add test8.0.1
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--.gitignore2
-rw-r--r--Makefile15
-rw-r--r--test.c6
-rwxr-xr-xtest.sh50
4 files changed, 70 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index ce640f9..dda84e5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,5 @@
*.out
*.su
/adjbacklight
+/.testdir/
+/test
diff --git a/Makefile b/Makefile
index d88ecc7..a179778 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
CONFIGFILE = config.mk
include $(CONFIGFILE)
-all: adjbacklight
+all: adjbacklight test
adjbacklight.o: adjbacklight.c arg.h
$(CC) -c -o adjbacklight.o adjbacklight.c $(CCFLAGS) $(CPPFLAGS)
@@ -11,6 +11,15 @@ adjbacklight.o: adjbacklight.c arg.h
adjbacklight: adjbacklight.o
$(CC) -o adjbacklight adjbacklight.o $(LDFLAGS)
+test.o: test.c adjbacklight.c arg.h
+ $(CC) -c -o test.o test.c $(CCFLAGS) $(CPPFLAGS)
+
+test: test.o
+ $(CC) -o test test.o $(LDFLAGS)
+
+check:
+ ./test.sh
+
install: adjbacklight
mkdir -p -- "$(DESTDIR)$(PREFIX)/bin"
mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man1"
@@ -27,6 +36,6 @@ uninstall:
-rmdir -- "$(DESTDIR)$(PREFIX)/share/licenses/adjbacklight"
clean:
- -rm -- adjbacklight *.o
+ -rm -r -- adjbacklight test *.o .testdir
-.PHONY: all install uninstall clean
+.PHONY: all check install uninstall clean
diff --git a/test.c b/test.c
new file mode 100644
index 0000000..e559f64
--- /dev/null
+++ b/test.c
@@ -0,0 +1,6 @@
+/* See LICENSE file for copyright and license details. */
+#ifdef BACKLIGHT_DIR
+# undef BACKLIGHT_DIR
+#endif
+#define BACKLIGHT_DIR ".testdir"
+#include "adjbacklight.c"
diff --git a/test.sh b/test.sh
new file mode 100755
index 0000000..89ea6cb
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+set -v
+set -e
+
+if test -d .testdir; then
+ rm -r .testdir
+fi
+
+mkdir -p .testdir/dev
+printf '%i\n' 50 > .testdir/dev/max_brightness
+printf '%i\n' 25 > .testdir/dev/brightness
+
+test $(./test -ga) = 50.00%
+test $(./test -g dev) = 50.00%
+
+./test -s +30 dev
+test $(./test -ga) = 100.00%
+
+./test -s 5 dev
+test $(./test -ga) = 10.00%
+
+./test -s -1 dev
+test $(./test -ga) = 8.00%
+
+./test -s +100%% dev
+test $(./test -ga) = 16.00%
+
+./test -s -50%% dev
+test $(./test -ga) = 8.00%
+
+./test -s 200%% dev
+test $(./test -ga) = 16.00%
+
+./test -s 50% dev
+test $(./test -ga) = 50.00%
+
+./test -s -10% dev
+test $(./test -ga) = 40.00%
+
+./test -s +20% dev
+test $(./test -ga) = 60.00%
+
+mkdir .testdir/acpi_videox
+printf '%i\n' 50 > .testdir/acpi_videox/max_brightness
+printf '%i\n' 25 > .testdir/acpi_videox/brightness
+
+test $(./test -g) = 50.00%
+
+rm -r .testdir