src/mess/tools/messtest/testzpth.c
| r0 | r3166 | |
| 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 | |
| 18 | static 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 | |
| 48 | void 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 | |
| 133 | done: |
| 134 | if (apath != NULL) |
| 135 | astring_free(apath); |
| 136 | if (directory != NULL) |
| 137 | zippath_closedir(directory); |
| 138 | } |