From ead56534d1731f80fe780532d869419667d3734c Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 12 Aug 2021 16:43:11 +0200 Subject: [PATCH] Some tests --- debian/Manifest | 1 + src/server.c | 6 +-- src/tests/getchar | Bin 0 -> 17096 bytes src/tests/getchar.c | 104 ++++++++++++++++++++++++++++++++++++++++++++ src/tests/xml | Bin 0 -> 17080 bytes src/tests/xml.c | 65 +++++++++++++++++++++++++++ src/tests/xml.xml | 15 +++++++ 7 files changed, 188 insertions(+), 3 deletions(-) create mode 100755 src/tests/getchar create mode 100644 src/tests/getchar.c create mode 100755 src/tests/xml create mode 100644 src/tests/xml.c create mode 100644 src/tests/xml.xml diff --git a/debian/Manifest b/debian/Manifest index 27314c1..d7fcae4 100644 --- a/debian/Manifest +++ b/debian/Manifest @@ -2,6 +2,7 @@ Package: gem-graph-server Version: 0.0.1 Section: custom Priority: optional +Depends: libxml2 Architecture: amd64 Essential: no Installed-Size: 1049 diff --git a/src/server.c b/src/server.c index c898066..40219c4 100644 --- a/src/server.c +++ b/src/server.c @@ -87,7 +87,7 @@ void *serverCommunicationInstance(void *server) clientPort, receiveBuff); - if (receiveBuff[0] == '\0') + if (receiveBuff[0] == '\0') //XXX break; // get args in an array @@ -222,10 +222,10 @@ static void *serverMain(void *server) clientIP, socklen); printLog("Client accepted from %s:%d\n", clientIP, - ntohs(serverSlots[serverSlotIndex].clientAddr.sin_port)); + ntohs(serverSlots[serverSlotIndex].clientAddr.sin_port)); // TODO envisager déplacement dans thread // Populate communicator slot - serverSlots[serverSlotIndex].socklen = socklen; + serverSlots[serverSlotIndex].socklen = socklen; // XXX serverSlots[serverSlotIndex].sockfd = connfd; serverSlots[serverSlotIndex].parent = args; diff --git a/src/tests/getchar b/src/tests/getchar new file mode 100755 index 0000000000000000000000000000000000000000..79b5550f461522eae1012f175b3bdf6eb7fd6005 GIT binary patch literal 17096 zcmeHOdu&_P89$EuNMBA$TNYZNZfUi2UEHM5QrczMN!&V9`dCS!6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KYmFHY$v^Z*2&yZ*R3rAFr|K~lQqmBgG)a5B4 z8)C$wVKb}`8rdbzBSH=-*{Q=nd_KvcU_TvXM6+q5C!C7X$)Wa*u*3@vBbSXKZ5Mk? z7elDSPY!Q8vRNHX9#<+Ibh4?H&O_Ny!@#*EzGifwsq85wJ{#pQwVtA~iG(k^D`|#z zfSMUad$@*ETd_>9@TJmb%-5aD`F7;uIJ_5+YADds-e88ig_QM#anj2d-IanrMRA@> zO74hdvUJSL${3JkVu>&r=vr^W6h4_bAF96YG*~mX6Q6V&Kq)P+u`kx62Yyc!PMA}s z>JCsATt|d(G9E$rv`L=PI2tQHTngdCJ($F;#W(W*Mrl2TM;yMZRN;9pQ(jMLvDD={ z(W~%JYZ$iY`7qN(q+}`ld}e4RDpq@*H#7CJqNYy!HsBv)O~dhde$BLA+v(*`Xecqn_G?(|Mul?9_PkDD%Ii>$@9h6Q+P+0Q?9&rCrh^(M zds_QC?e7CdIpKL9eU;0iDcM+y^ZMr@wAy>M9n*tWW7Hk)#g82JypCbY?PWL2GySQ< zeozNsddRWf`6Ms8Igc-gzFo zjTJR@#-|O(R(oELF|8+|r8wh13mIlPJQN?z6{$Mi#@OJMj8O3u%6;B z@{GR@0gXMrOuP={bMQmD{X9O|j<4ebuq73?=k?;5WdKp?6)AnPJ=3=#vDyp2R&7*t zt7e(79n%jXu-fxHd#kqRb~^2u{}dJS#qH<$X3yueSL+{~gJp-Bvi+AGxK5{RGl_`j zv1e61s2z^z#MAc>rIh>4&tJMfxb0T^K3eFa9CbM7_)1D^hw}DcTdg!EI}9AG_%}DV B3331c literal 0 HcmV?d00001 diff --git a/src/tests/getchar.c b/src/tests/getchar.c new file mode 100644 index 0000000..37ae5d0 --- /dev/null +++ b/src/tests/getchar.c @@ -0,0 +1,104 @@ +#include "../../include/base.h" +#include +#include +#include +#include + +#define KEY_ESCAPE 27 +#define KEY_DIRECTIONS 91 +#define KEY_ARROW_UP 65 +#define KEY_ARROW_DOWN 66 +#define KEY_ARROW_RIGHT 67 +#define KEY_ARROW_LEFT 68 +#define KEY_DELETE 127 + +#define C_CLEARSCREEN "\e[2J" +#define C_CLEARLINE "\e[2K" +#define C_CURSORLEFT "\e[1D" +#define C_CURSORRIGHT "\e[1C" +#define C_SAVE_CURSORPOS "\e7" +#define C_RESTORE_CURSORPOS "\e8" +#define C_COLOR_RED "\e[01;31m" +#define C_COLOR_YELLOW "\e[00;33m" +#define C_COLOR_GREEN "\e[00;32m" +#define C_COLOR_BLUE "\e[01;34m" +#define C_COLOR_REVERSE "\e[7m" +#define C_COLOR_NORMAL "\e[0m" + +// +// Get a character code from the keyboard +// +static inline int getch(bool nonBlocking) +{ + int buf = 0; + // old terminal + struct termios old = {0}; + + // force flush stdout + fflush(stdout); + + // Set non-blocking mode if asked + if(nonBlocking) + fcntl(0, F_SETFL, O_NONBLOCK); + + if(tcgetattr(0, &old) < 0) { + printLog("%sError getting terminal settings! (%s)\n", + C_COLOR_RED, + strerror(errno)); + return -1; + } + + old.c_lflag &= ~ICANON; // disable buffered I/O + old.c_lflag &= ~ECHO; // set no echo mode + + if(tcsetattr(0, TCSANOW, &old) < 0) { + printLog("%sError setting terminal settings! (%s)\n", + C_COLOR_RED, + strerror(errno)); + return -1; + } + + buf = getchar(); + if(buf < 0) { + // Check target busy (try again) + if(errno == EAGAIN) + return 0; + + printLog("%sError reading character! (%s)\n", + C_COLOR_RED, + strerror(errno)); + return -1; + } + + old.c_lflag |= ICANON; // enable buffered I/O + old.c_lflag |= ECHO; // set echo mode + + if(tcsetattr(0, TCSADRAIN, &old) < 0) { + printLog("%sError resetting terminal settings! (%s)\n", + C_COLOR_RED, + strerror(errno)); + return -1; + } + + // Reset blocking mode + if(nonBlocking) + fcntl(0, F_SETFL, 0); + + return buf; + } + + +int main(void) +{ + + + while(1) { + int c = getch(1); + + if (c > 0) + printf("touche %d\n", c); + + } + + return 0; +} diff --git a/src/tests/xml b/src/tests/xml new file mode 100755 index 0000000000000000000000000000000000000000..04cd32f658a22b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guqDnq)I+?4yClBnO?wZmZ@cp3)-xVYUs{?PNm ibyt?^cPA}ykxqJ?bGb@NYm(yjfptn_mdC)uihluz@&i`@ literal 0 HcmV?d00001 diff --git a/src/tests/xml.c b/src/tests/xml.c new file mode 100644 index 0000000..bcba914 --- /dev/null +++ b/src/tests/xml.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include + +void parseStory (xmlDocPtr doc, xmlNodePtr cur) +{ + cur = cur->xmlChildrenNode; + while (cur != NULL) { + if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyword"))) { + printf("keyword: %s\n", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); + } + cur = cur->next; + } + return; +} + +static void parseDoc(char *docname) +{ + xmlDocPtr doc; + xmlNodePtr cur; + doc = xmlParseFile(docname); + if (doc == NULL ) { + fprintf(stderr,"Document not parsed successfully. \n"); + xmlFreeDoc(doc); + return; + } + + cur = xmlDocGetRootElement(doc); + if (cur == NULL) { + fprintf(stderr,"empty document\n"); + xmlFreeDoc(doc); + return; + } + if (xmlStrcmp(cur->name, (const xmlChar *) "story")) { + fprintf(stderr,"document of the wrong type, root node != story"); + xmlFreeDoc(doc); + return; + } + cur = cur->xmlChildrenNode; + while (cur != NULL) { + if ((!xmlStrcmp(cur->name, (const xmlChar *)"storyinfo"))){ + parseStory (doc, cur); + } + cur = cur->next; + } + xmlFreeDoc(doc); + return; +} + +int main(int argc, char **argv) +{ + char *docname; + if (argc <= 1) { + printf("Usage: %s docname\n", argv[0]); + return 1; + } + + docname = argv[1]; + parseDoc (docname); + + return 0; +} + diff --git a/src/tests/xml.xml b/src/tests/xml.xml new file mode 100644 index 0000000..748e53c --- /dev/null +++ b/src/tests/xml.xml @@ -0,0 +1,15 @@ + + + + John Fleck + June 2, 2002 + example keyword + + + + This is the headline + This is the body text. + + + +