Previous 15994 Revisions Next

r3166 Thursday 4th September, 2008 at 10:52:09 UTC by Nathan Woods
Created a facility to test zippath.c
[src/mess/tools/messtest]core.c messtest.mak testimgt.h testmess.h testzpth.c* testzpth.h*

src/mess/tools/messtest/testimgt.h
r3165r3166
66
77*********************************************************************/
88
9#ifndef TESTIMGT_H
10#define TESTIMGT_H
9#ifndef __TESTIMGT_H__
10#define __TESTIMGT_H__
1111
1212#include "xmlfile.h"
1313#include "core.h"
1414
1515void node_testimgtool(xml_data_node *node);
1616
17#endif /* TESTIMGT_H */
17#endif /* __TESTIMGT_H__ */
src/mess/tools/messtest/testzpth.c
r0r3166
1/*********************************************************************
2
3   testzpth.c
4
5   Code for testing zip paths
6
7*********************************************************************/
8
9#include "testzpth.h"
10#include "zippath.h"
11
12
13/*-------------------------------------------------
14    dir_entry_type_string - gets a string
15   representation of a osd_dir_entry_type
16-------------------------------------------------*/
17
18static const char *dir_entry_type_string(osd_dir_entry_type type)
19{
20   const char *s;
21   switch(type)
22   {
23      case ENTTYPE_NONE:
24         s = "none";
25         break;
26      case ENTTYPE_FILE:
27         s = "file";
28         break;
29      case ENTTYPE_DIR:
30         s = "directory";
31         break;
32      case ENTTYPE_OTHER:
33         s = "other";
34         break;
35      default:
36         s = "???";
37         break;
38   }
39   return s;
40}
41
42
43
44/*-------------------------------------------------
45    node_testzippath - test a zip path
46-------------------------------------------------*/
47
48void node_testzippath(xml_data_node *node)
49{
50   xml_attribute_node *attr_node;
51   xml_data_node *first_child_node;
52   xml_data_node *child_node;
53   const char *path;
54   const char *plus;
55   astring *apath = NULL;
56   zippath_directory *directory = NULL;
57   const osd_directory_entry *dirent;
58   const char *type_string;
59   file_error err;
60   UINT64 size;
61
62   /* name the test case */
63   report_testcase_begin("zippath");
64
65   /* retrieve path */
66   attr_node = xml_get_attribute(node, "path");
67   path = (attr_node != NULL) ? attr_node->value : "";
68
69   /* retrieve 'plus' - for testing zippath_combine */
70   attr_node = xml_get_attribute(node, "plus");
71   if (attr_node != NULL)
72   {
73      plus = attr_node->value;
74      apath = zippath_combine(astring_alloc(), path, plus);
75      report_message(MSG_INFO, "Testing ZIP Path '%s' + '%s' ==> '%s'", path, plus, astring_c(apath));
76   }
77   else
78   {
79      apath = astring_cpyc(astring_alloc(), path);
80      report_message(MSG_INFO, "Testing ZIP Path '%s'", astring_c(apath));
81   }
82
83   /* try doing a directory listing */
84   first_child_node = xml_get_sibling(node->child, "entry");
85   if (first_child_node != NULL)
86   {
87      err = zippath_opendir(astring_c(apath), &directory);
88      if (err != FILERR_NONE)
89      {
90         report_message(MSG_FAILURE, "Error %d opening directory", (int) err);
91         goto done;
92      }
93
94      /* read each directory entry */
95      while((dirent = zippath_readdir(directory)) != NULL)
96      {
97         /* find it in the list */
98         for (child_node = first_child_node; child_node != NULL; child_node = xml_get_sibling(child_node->next, "entry"))
99         {
100            attr_node = xml_get_attribute(child_node, "name");
101            if ((attr_node != NULL) && !strcmp(attr_node->value, dirent->name))
102               break;
103         }
104
105         /* did we find the node? */
106         if (child_node != NULL)
107         {
108            /* check dirent type */
109            attr_node = xml_get_attribute(child_node, "type");
110            if (attr_node != NULL)
111            {
112               type_string = dir_entry_type_string(dirent->type);
113               if (mame_stricmp(attr_node->value, type_string))
114                  report_message(MSG_FAILURE, "Expected '%s' to be '%s', but instead got '%s'", dirent->name, attr_node->value, type_string);
115            }
116
117            /* check size */
118            attr_node = xml_get_attribute(child_node, "size");
119            if (attr_node != NULL)
120            {
121               size = atoi(attr_node->value);
122               if (size != dirent->size)
123                  report_message(MSG_FAILURE, "Expected '%s' to be of size '%ld', but instead got '%ld'", dirent->name, (long) size, (long) dirent->size);
124            }
125         }
126         else
127         {
128            report_message(MSG_FAILURE, "Unexpected directory entry '%s'", dirent->name);
129         }
130      }
131   }
132
133done:
134   if (apath != NULL)
135      astring_free(apath);
136   if (directory != NULL)
137      zippath_closedir(directory);
138}
src/mess/tools/messtest/core.c
r3165r3166
1717#include "core.h"
1818#include "testmess.h"
1919#include "testimgt.h"
20#include "testzpth.h"
2021#include "osdepend.h"
2122#include "pool.h"
2223#include "pile.h"
r3165r3166
477478         if (is_failure)
478479            (*failure_count)++;
479480      }
481      else if (!strcmp(child_node->name, "zippathtest"))
482      {
483         /* a zippath test */
484         node_testzippath(child_node);
485
486         (*test_count)++;
487         if (is_failure)
488            (*failure_count)++;
489      }
480490   }
481491}
482492
src/mess/tools/messtest/testzpth.h
r0r3166
1/*********************************************************************
2
3   testzpth.h
4
5   Code for testing zip paths
6
7*********************************************************************/
8
9#ifndef __TESTZPTH_H__
10#define __TESTZPTH_H__
11
12#include "xmlfile.h"
13#include "core.h"
14
15void node_testzippath(xml_data_node *node);
16
17#endif /* __TESTZPTH_H__ */
src/mess/tools/messtest/testmess.h
r3165r3166
66
77*********************************************************************/
88
9#ifndef TESTMESS_H
10#define TESTMESS_H
9#ifndef __TESTMESS_H__
10#define __TESTMESS_H__
1111
1212#include "xmlfile.h"
1313#include "core.h"
1414
1515void node_testmess(xml_data_node *node);
1616
17#endif /* TESTMESS_H */
17#endif /* __TESTMESS_H__ */
src/mess/tools/messtest/messtest.mak
r3165r3166
2525   $(MESSOBJ)/tools/messtest/core.o      \
2626   $(MESSOBJ)/tools/messtest/testmess.o   \
2727   $(MESSOBJ)/tools/messtest/testimgt.o   \
28   $(MESSOBJ)/tools/messtest/testzpth.o   \
2829   $(MESSOBJ)/tools/messtest/tststubs.o   \
2930   $(MESSOBJ)/tools/messtest/tstutils.o   \
3031

Previous 15994 Revisions Next


© 1998-2018 The MESS Team