From d1e587a9cd06a9cf5f619642ec17506d589c687b Mon Sep 17 00:00:00 2001 From: Dmitry Isaikin Date: Tue, 9 Feb 2016 13:48:03 +0300 Subject: Some tests for MessageBuilder::writeToFile --- tests/test-all.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test-all.cpp b/tests/test-all.cpp index 1858bef1..ba79a3ea 100644 --- a/tests/test-all.cpp +++ b/tests/test-all.cpp @@ -63,6 +63,16 @@ class TestCallback : public mailcore::Object, public mailcore::OperationCallback } }; +static mailcore::String * temporaryFilenameForTest() +{ + char tempfile[] = "/tmp/mailcore2-test-XXXXXX"; + char * result = mktemp(tempfile); + if (result == NULL) { + return NULL; + } + return mailcore::String::stringWithFileSystemRepresentation(tempfile); +} + static mailcore::Data * testMessageBuilder() { mailcore::Address * address = new mailcore::Address(); @@ -96,7 +106,12 @@ static mailcore::Data * testMessageBuilder() mailcore::Data * data = msg->data(); MCLog("%s", data->bytes()); - + + mailcore::String *filename = temporaryFilenameForTest(); + msg->writeToFile(filename); + mailcore::Data *fileData = mailcore::Data::dataWithContentsOfFile(filename); + MCAssert(data->isEqual(fileData)); + mailcore::MessageBuilder * msg2 = new mailcore::MessageBuilder(msg); mailcore::String *htmlBody = msg->htmlBody(); mailcore::String *htmlBody2 = msg2->htmlBody(); @@ -104,7 +119,8 @@ static mailcore::Data * testMessageBuilder() msg->release(); msg2->release(); - + unlink(filename->fileSystemRepresentation()); + return data; } -- cgit v1.2.3