void linkArchive(TArchive & ar, const int v=0) { ar & nvp("x", x) & nvp("y", y); }
void testCreateMultipart() { #define BODY1 \ "Now is the time for all good men to come to the aid of their party." #define HEADER \ "Content-Type: multipart/related;" \ "boundary=\"[boundary]\"\r\n" \ "\r\n" #define PART1 \ "--[boundary]\r\n" \ "Content-ID: <*****@*****.**>\r\n" \ "CONTENT-TYPE: text/plain\r\n" \ "CONTENT-TRANSFER-ENCODING: binary\r\n" \ "\r\n" \ BODY1 \ "\r\n" #define FORMAT2 \ "--[boundary]\r\n" \ "CONTENT-TYPE: application/octet-stream\r\n" \ "CONTENT-TRANSFER-ENCODING: binary\r\n" \ "\r\n" \ "%s" \ "\r\n" #define TRAILER \ "--[boundary]--\r\n" HttpBodyMultipart body("multipart/related"); ASSERT_STR_EQUAL_MESSAGE("Zero body parts", HEADER TRAILER, extract_contents(&body).data()); HttpBody bodyPart1(BODY1, sizeof (BODY1) - 1, "text/plain"); UtlDList parameters1; NameValuePair nvp("Content-ID", "<*****@*****.**>"); parameters1.append(&nvp); body.appendBodyPart(bodyPart1, parameters1); ASSERT_STR_EQUAL_MESSAGE("One body part", HEADER PART1 TRAILER, extract_contents(&body).data()); // Find the current boundary string and use it as a body, // forcing the HttpBody to change the boundary string. char boundary_string[10]; strcpy(boundary_string, body.getMultipartBoundary()); HttpBody bodyPart2(boundary_string, strlen(boundary_string), "application/octet-stream"); UtlDList parameters2; body.appendBodyPart(bodyPart2, parameters2); char part2[1024]; sprintf(part2, HEADER PART1 FORMAT2 TRAILER, boundary_string); ASSERT_STR_EQUAL_MESSAGE("Two body parts", part2, extract_contents(&body).data()); const char* new_boundary_string = body.getMultipartBoundary(); CPPUNIT_ASSERT_MESSAGE("Changed boundary string", strcmp(boundary_string, new_boundary_string)); }