@@ -13,52 +13,27 @@
* file.
*/
#include "config.h"
-#import "TestsAppDelegate.h"
+#import "ObjFW.h"
+#import "ObjFWTest.h"
+
+@interface OFPropertyListTests: OTTestCase
+@end
#define PLIST(x) \
@"" \
@"" \
@"\n" \
x @"\n" \
@""
-static OFString *const module = @"OFPropertyList";
-static OFString *const PLIST1 = PLIST(@"Hello");
-static OFString *const PLIST2 = PLIST(
- @""
- @" Hello"
- @" V29ybGQh"
- @" 2018-03-14T12:34:56Z"
- @" "
- @" "
- @" 12.25"
- @" -10"
- @"");
-static OFString *const PLIST3 = PLIST(
- @""
- @" array"
- @" "
- @" Hello"
- @" V29ybGQh"
- @" 2018-03-14T12:34:56Z"
- @" "
- @" "
- @" 12.25"
- @" -10"
- @" "
- @" foo"
- @" bar"
- @"");
-
-@implementation TestsAppDelegate (OFPLISTParser)
-- (void)propertyListTests
-{
- void *pool = objc_autoreleasePoolPush();
+@implementation OFPropertyListTests
+- (void)testObjectByParsingPropertyList
+{
OFArray *array = [OFArray arrayWithObjects:
@"Hello",
[OFData dataWithItems: "World!" count: 6],
[OFDate dateWithTimeIntervalSince1970: 1521030896],
[OFNumber numberWithBool: true],
@@ -65,54 +40,101 @@
[OFNumber numberWithBool: false],
[OFNumber numberWithFloat: 12.25f],
[OFNumber numberWithInt: -10],
nil];
- TEST(@"-[objectByParsingPropertyList:] #1",
- [PLIST1.objectByParsingPropertyList isEqual: @"Hello"])
-
- TEST(@"-[objectByParsingPropertyList:] #2",
- [PLIST2.objectByParsingPropertyList isEqual: array])
-
- TEST(@"-[objectByParsingPropertyList:] #3",
- [PLIST3.objectByParsingPropertyList isEqual:
- [OFDictionary dictionaryWithKeysAndObjects:
+ OTAssertEqualObjects([PLIST(
+ @"Hello") objectByParsingPropertyList],
+ @"Hello");
+ OTAssertEqualObjects([PLIST(
+ @""
+ @" Hello"
+ @" V29ybGQh"
+ @" 2018-03-14T12:34:56Z"
+ @" "
+ @" "
+ @" 12.25"
+ @" -10"
+ @"") objectByParsingPropertyList],
+ array);
+ OTAssertEqualObjects([PLIST(
+ @""
+ @" array"
+ @" "
+ @" Hello"
+ @" V29ybGQh"
+ @" 2018-03-14T12:34:56Z"
+ @" "
+ @" "
+ @" 12.25"
+ @" -10"
+ @" "
+ @" foo"
+ @" bar"
+ @"") objectByParsingPropertyList],
+ ([OFDictionary dictionaryWithKeysAndObjects:
@"array", array,
@"foo", @"bar",
- nil]])
-
- EXPECT_EXCEPTION(@"Detecting unsupported version",
- OFUnsupportedVersionException,
- [[PLIST(@"") stringByReplacingOccurrencesOfString: @"1.0"
- withString: @"1.1"]
- objectByParsingPropertyList])
-
- EXPECT_EXCEPTION(
- @"-[objectByParsingPropertyList] detecting invalid format #1",
- OFInvalidFormatException,
- [PLIST(@"") objectByParsingPropertyList])
-
- EXPECT_EXCEPTION(
- @"-[objectByParsingPropertyList] detecting invalid format #2",
- OFInvalidFormatException,
- [PLIST(@"") objectByParsingPropertyList])
-
- EXPECT_EXCEPTION(
- @"-[objectByParsingPropertyList] detecting invalid format #3",
- OFInvalidFormatException,
- [PLIST(@"") objectByParsingPropertyList])
-
- EXPECT_EXCEPTION(
- @"-[objectByParsingPropertyList] detecting invalid format #4",
- OFInvalidFormatException,
- [PLIST(@"")
- objectByParsingPropertyList])
-
- EXPECT_EXCEPTION(
- @"-[objectByParsingPropertyList] detecting invalid format #5",
- OFInvalidFormatException,
- [PLIST(@"")
- objectByParsingPropertyList])
-
- objc_autoreleasePoolPop(pool);
+ nil]));
+}
+
+- (void)testDetectUnsupportedVersion
+{
+ bool caught = false;
+ @try {
+ [[PLIST(@"")
+ stringByReplacingOccurrencesOfString: @"1.0"
+ withString: @"1.1"]
+ objectByParsingPropertyList];
+ } @catch (OFUnsupportedVersionException *e) {
+ caught = true;
+ }
+ OTAssertTrue(caught);
+}
+
+- (void)testDetectInvalidFormat
+{
+ bool caught;
+
+ caught = false;
+ @try {
+ [PLIST(@"") objectByParsingPropertyList];
+ } @catch (OFInvalidFormatException *e) {
+ caught = true;
+ }
+ OTAssertTrue(caught);
+
+ caught = false;
+ @try {
+ [PLIST(@"") objectByParsingPropertyList];
+ } @catch (OFInvalidFormatException *e) {
+ caught = true;
+ }
+ OTAssertTrue(caught);
+
+ caught = false;
+ @try {
+ [PLIST(@"") objectByParsingPropertyList];
+ } @catch (OFInvalidFormatException *e) {
+ caught = true;
+ }
+ OTAssertTrue(caught);
+
+ caught = false;
+ @try {
+ [PLIST(@"")
+ objectByParsingPropertyList];
+ } @catch (OFInvalidFormatException *e) {
+ caught = true;
+ }
+ OTAssertTrue(caught);
+
+ caught = false;
+ @try {
+ [PLIST(@"")
+ objectByParsingPropertyList];
+ } @catch (OFInvalidFormatException *e) {
+ caught = true;
+ }
+ OTAssertTrue(caught);
}
@end