| 5 | #include "acl_cpp/lib_acl.hpp" |
| 6 | |
| 7 | static void test_parse(const char* path, const char* boundary) |
| 8 | { |
| 9 | acl::http_mime mime(boundary); |
| 10 | mime.set_saved_path(path); |
| 11 | acl::string buf; |
| 12 | |
| 13 | if (acl::ifstream::load(path, &buf) == false) { |
| 14 | printf("load %s error\r\n", path); |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | mime.update(buf.c_str(), buf.length()); |
| 19 | #if 1 |
| 20 | const std::list<acl::http_mime_node*>& nodes = mime.get_nodes(); |
| 21 | for (std::list<acl::http_mime_node*>::const_iterator cit = nodes.begin(); |
| 22 | cit != nodes.end(); ++cit) { |
| 23 | acl::http_mime_node* node = *cit; |
| 24 | if (node->get_mime_type() == acl::HTTP_MIME_PARAM) { |
| 25 | const char* name = node->get_name(); |
| 26 | const char* value = node->get_value(); |
| 27 | printf("name: %s, value: %s\r\n", name ? name : "null", |
| 28 | value ? value : "null"); |
| 29 | } else if (node->get_mime_type() == acl::HTTP_MIME_FILE) { |
| 30 | const char* filename = node->get_filename(); |
| 31 | printf("filename: %s\r\n", filename ? filename : "null"); |
| 32 | (void) node->save(filename); |
| 33 | } |
| 34 | } |
| 35 | #endif |
| 36 | |
| 37 | #if 1 |
| 38 | printf("length: %d\r\n", (int) buf.length()); |
| 39 | const std::list<acl::http_mime_node*>& nodes2 = mime.get_nodes(); |
| 40 | for (std::list<acl::http_mime_node*>::const_iterator cit = nodes2.begin(); |
| 41 | cit != nodes2.end(); ++cit) { |
| 42 | const char* n1, *f, *v; |
| 43 | n1 = (*cit)->get_name(); |
| 44 | f = (*cit)->get_filename(); |
| 45 | v = (*cit)->get_value(); |
| 46 | printf(">>>name: %s, value: %s, file: %s<br>\r\n", |
| 47 | n1 ? n1 : "null", v ? v : "null", f ? f : "null"); |
| 48 | } |
| 49 | |
| 50 | const acl::http_mime_node* node = mime.get_node("file_0"); |
| 51 | if (node == NULL || node->get_mime_type() != acl::HTTP_MIME_FILE) { |
| 52 | printf("filename not found\r\n"); |
| 53 | return; |
| 54 | } |
| 55 | const char* ptr = node->get_filename(); |
| 56 | if (ptr == NULL || *ptr == 0) { |
| 57 | printf("filename's value null\r\n"); |
| 58 | } else { |
| 59 | printf("filename: %s\r\n", ptr); |
| 60 | } |
| 61 | #endif |
| 62 | } |
| 63 | |
| 64 | static void test_build(const char* file, const char* boundary) { |
no test coverage detected
searching dependent graphs…