Some tests

This commit is contained in:
Adrien Bourmault 2021-08-12 16:43:11 +02:00
parent 7ba450380f
commit ead56534d1
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
7 changed files with 188 additions and 3 deletions

1
debian/Manifest vendored
View File

@ -2,6 +2,7 @@ Package: gem-graph-server
Version: 0.0.1 Version: 0.0.1
Section: custom Section: custom
Priority: optional Priority: optional
Depends: libxml2
Architecture: amd64 Architecture: amd64
Essential: no Essential: no
Installed-Size: 1049 Installed-Size: 1049

View File

@ -87,7 +87,7 @@ void *serverCommunicationInstance(void *server)
clientPort, clientPort,
receiveBuff); receiveBuff);
if (receiveBuff[0] == '\0') if (receiveBuff[0] == '\0') //XXX
break; break;
// get args in an array // get args in an array
@ -222,10 +222,10 @@ static void *serverMain(void *server)
clientIP, socklen); clientIP, socklen);
printLog("Client accepted from %s:%d\n", printLog("Client accepted from %s:%d\n",
clientIP, clientIP,
ntohs(serverSlots[serverSlotIndex].clientAddr.sin_port)); ntohs(serverSlots[serverSlotIndex].clientAddr.sin_port)); // TODO envisager déplacement dans thread
// Populate communicator slot // Populate communicator slot
serverSlots[serverSlotIndex].socklen = socklen; serverSlots[serverSlotIndex].socklen = socklen; // XXX
serverSlots[serverSlotIndex].sockfd = connfd; serverSlots[serverSlotIndex].sockfd = connfd;
serverSlots[serverSlotIndex].parent = args; serverSlots[serverSlotIndex].parent = args;

BIN
src/tests/getchar Executable file

Binary file not shown.

104
src/tests/getchar.c Normal file
View File

@ -0,0 +1,104 @@
#include "../../include/base.h"
#include <sys/ioctl.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#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;
}

BIN
src/tests/xml Executable file

Binary file not shown.

65
src/tests/xml.c Normal file
View File

@ -0,0 +1,65 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml2/libxml/xmlmemory.h>
#include <libxml2/libxml/parser.h>
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;
}

15
src/tests/xml.xml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<story>
<storyinfo>
<author>John Fleck</author>
<datewritten>June 2, 2002</datewritten>
<keyword>example keyword</keyword>
</storyinfo>
<body>
<headline>This is the headline</headline>
<para>This is the body text.</para>
</body>
</story>