summaryrefslogtreecommitdiffabout
path: root/test
authorMichael Krelin <hacker@klever.net>2008-04-05 11:17:33 (UTC)
committer Michael Krelin <hacker@klever.net>2008-04-05 11:17:33 (UTC)
commit04fb190243442e83349f129b523ab747e58100bf (patch) (unidiff)
treeddc28357fbe78b07fd3a5e0aa8088130bf305829 /test
downloadnapkin-04fb190243442e83349f129b523ab747e58100bf.zip
napkin-04fb190243442e83349f129b523ab747e58100bf.tar.gz
napkin-04fb190243442e83349f129b523ab747e58100bf.tar.bz2
Initial commit into public repository0.0
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'test') (more/less context) (ignore whitespace changes)
-rw-r--r--test/.gitignore4
-rw-r--r--test/Makefile.am7
-rw-r--r--test/sleeptracker-decode.cc49
3 files changed, 60 insertions, 0 deletions
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 0000000..579d0cc
--- a/dev/null
+++ b/test/.gitignore
@@ -0,0 +1,4 @@
1/sleeptracker-decode
2/sleeptracker-decode.o
3/.libs
4/.deps
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..09c3ed7
--- a/dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,7 @@
1noinst_PROGRAMS = sleeptracker-decode
2
3INCLUDES = -I${top_srcdir}/include/ ${MODULES_CFLAGS}
4LIBS = ${top_builddir}/lib/libnapkin.la
5
6sleeptracker_decode_SOURCES = sleeptracker-decode.cc
7sleeptracker_decode_DEPENDENCIES = ${LIBS}
diff --git a/test/sleeptracker-decode.cc b/test/sleeptracker-decode.cc
new file mode 100644
index 0000000..77d4fbd
--- a/dev/null
+++ b/test/sleeptracker-decode.cc
@@ -0,0 +1,49 @@
1#include <sys/types.h>
2#include <sys/stat.h>
3#include <fcntl.h>
4#include <unistd.h>
5#include <termios.h>
6#include <iostream>
7#include <stdexcept>
8#include <algorithm>
9#include <iterator>
10using namespace std;
11#include <napkin/st/decode.h>
12
13string str_f_time(const char *fmt,time_t t) {
14 struct tm tt;
15 localtime_r(&t,&tt);
16 char rv[1024];
17 strftime(rv,sizeof(rv),fmt,&tt);
18 return rv;
19}
20
21ostream& operator<<(ostream& o,const napkin::hypnodata_t& hd) {
22 o
23 << "Window is " << hd.window << endl
24 << "'To bed' time is " << str_f_time("%Y-%m-%d %H:%M",hd.to_bed) << endl
25 << "Alarm time is " << str_f_time("%Y-%m-%d %H:%M",hd.alarm) << endl
26 << "Data A is " << hd.data_a/60 << ":" << hd.data_a%60 << endl;
27 for(vector<time_t>::const_iterator i=hd.almost_awakes.begin();i!=hd.almost_awakes.end();++i)
28 o << " almost awake at " << str_f_time("%Y-%m-%d %H:%M:%S",*i) << endl;
29 return o;
30}
31
32int main(int/*argc*/,char **argv) {
33 try {
34 int fd = open(argv[1],O_RDONLY);
35 if(fd<0)
36 throw runtime_error("failed to open() data");
37 unsigned char buffer[1024];
38 int rb = read(fd,buffer,sizeof(buffer));
39 if(!(rb>0))
40 throw runtime_error("failed to read() data");
41 close(fd);
42
43 napkin::hypnodata_t hd;
44 cout << napkin::sleeptracker::decode(hd,buffer,rb);
45 }catch(exception& e) {
46 cerr << "oops: " << e.what() << endl;
47 }
48}
49