Updated Branches: refs/heads/master 2ad214abf -> 0561c6ba8
Added/renamed CDVExifTests to project. Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/0561c6ba Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/0561c6ba Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/0561c6ba Branch: refs/heads/master Commit: 0561c6ba8bf4eaaa0086d6dea27bb37b3150974b Parents: 2ad214a Author: Shazron Abdullah <[email protected]> Authored: Mon Jun 3 14:57:14 2013 -0700 Committer: Shazron Abdullah <[email protected]> Committed: Mon Jun 3 14:57:14 2013 -0700 ---------------------------------------------------------------------- CordovaLibTests/CDVExifTests.h | 38 ++++ CordovaLibTests/CDVExifTests.m | 171 ++++++++++++++ .../CordovaTests.xcodeproj/project.pbxproj | 6 + CordovaLibTests/ExifTests.h | 38 ---- CordovaLibTests/ExifTests.m | 172 --------------- 5 files changed, 215 insertions(+), 210 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/0561c6ba/CordovaLibTests/CDVExifTests.h ---------------------------------------------------------------------- diff --git a/CordovaLibTests/CDVExifTests.h b/CordovaLibTests/CDVExifTests.h new file mode 100644 index 0000000..2f41c4c --- /dev/null +++ b/CordovaLibTests/CDVExifTests.h @@ -0,0 +1,38 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ + +#import <SenTestingKit/SenTestingKit.h> + +#import <Cordova/CDVJpegHeaderWriter.h> + +#define ARC4RANDOM_MAX 0x100000000 + +@interface CDVExifTests : SenTestCase { + CDVJpegHeaderWriter* testHeaderWriter; + NSNumber* testErrorThreshhold; +} + +- (void)testContinuedFractionWithUInt; +- (void)testContinuedFractionWithUFloat; +- (void)testContinuedFractionsWorstCase; +- (void)testFormatHexFromDecimal; +- (void)testFormatNumberWithLeadingZeroes; +- (void)testUnsignedRationalToString; +- (void)testSignedRationalToString; +@end http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/0561c6ba/CordovaLibTests/CDVExifTests.m ---------------------------------------------------------------------- diff --git a/CordovaLibTests/CDVExifTests.m b/CordovaLibTests/CDVExifTests.m new file mode 100644 index 0000000..aa456c8 --- /dev/null +++ b/CordovaLibTests/CDVExifTests.m @@ -0,0 +1,171 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ + +#import <SenTestingKit/SenTestingKit.h> + +#import "CDVExifTests.h" + +@implementation CDVExifTests + +- (void)setUp +{ + [super setUp]; + testHeaderWriter = [[CDVJpegHeaderWriter alloc] init]; + testErrorThreshhold = [NSNumber numberWithDouble:0.000001]; + NSLog(@"%x", ~10 + 1); +} + +- (void)tearDown +{ + // Tear-down code here. + + [super tearDown]; +} + +// ================================================================================================== +// rational approximation of decimal by continued fraction tests +// ================================================================================================== + +// tests continued fraction with random int +- (void)testContinuedFractionWithUInt +{ + NSLog(@"Continued Fraction Test with random int value, numerator should be generated value, denominator should be 1"); + NSNumber* numerator = @0; + NSNumber* denominator = @0; + NSNumber* testValue = [NSNumber numberWithInt:abs(arc4random())]; + [testHeaderWriter decimalToUnsignedRational:testValue + withResultNumerator:&numerator + withResultDenominator:&denominator]; + STAssertEquals([numerator intValue], + [testValue intValue], + @"Numerator did not match"); + STAssertEquals([denominator intValue], + 1, + @"denominator was not one"); +} + +// tests continued fraction with random float +- (void)testContinuedFractionWithUFloat +{ + NSLog(@"Continued Fraction Test with random double value, resulting fraction should be within acceptable error threshhold"); + NSNumber* threshhold = @0.1; + NSNumber* numerator = @0; + NSNumber* denominator = @0; + NSLog(@"%f", ((double)arc4random() / ARC4RANDOM_MAX) * 100.0f); + NSNumber* testValue = [NSNumber numberWithDouble: + ((double)arc4random() / ARC4RANDOM_MAX) * 100.0f]; + + [testHeaderWriter decimalToUnsignedRational:testValue + withResultNumerator:&numerator + withResultDenominator:&denominator]; + NSLog(@"%lf, %lf", [testValue doubleValue], [numerator doubleValue] / [denominator doubleValue]); + + STAssertEqualsWithAccuracy([testValue doubleValue], + [numerator doubleValue] / [denominator doubleValue], + [threshhold doubleValue], + @"rational approximation did not meet acceptable error threshhold"); +} + +// tests continued fraction in sqrt(2) worst case +- (void)testContinuedFractionsWorstCase +{ + NSLog(@"Continued Fraction Test with provable worst case ~sqrt(2), resulting fraction should be within acceptable error threshhold"); + NSNumber* threshhold = @0.1; + NSNumber* numerator = @0; + NSNumber* denominator = @0; + NSNumber* testValue = [NSNumber numberWithDouble:sqrt(2)]; + [testHeaderWriter decimalToUnsignedRational:testValue + withResultNumerator:&numerator + withResultDenominator:&denominator]; + STAssertEqualsWithAccuracy([testValue doubleValue], + [numerator doubleValue] / [denominator doubleValue], + [threshhold doubleValue], + @"rational approximation did not meet acceptable error threshhold"); +} + +// tests format hex from a decimal +- (void)testFormatHexFromDecimal +{ + NSNumber* testValue = @1; + NSNumber* testPlaces = @8; + NSString* result = nil; + + result = [testHeaderWriter formattedHexStringFromDecimalNumber:testValue + withPlaces:testPlaces]; + // assert not nil + STAssertNotNil(result, @"nil renturned from formattedHexStringFromDecimalNumber"); + // assert correct number of places + STAssertEquals([result length], [testPlaces unsignedIntegerValue], + @"returned string to wrong number of places. Should be = %i Was = %i", + [testPlaces intValue], + [result length]); + // assert correct hex representation + STAssertTrueNoThrow([result isEqualToString:@"00000001"], @"result should be equal to @00000001"); +} + +// tests format number string with leading zeroes +- (void)testFormatNumberWithLeadingZeroes +{ + NSString* result = nil; + NSNumber* testValue = @8769; // Exif SubIFD Offset Tag + NSNumber* testPlaces = @6; + + result = [testHeaderWriter formatNumberWithLeadingZeroes:testValue + withPlaces:testPlaces]; + STAssertNotNil(result, @"nil renturned from formattedHexStringFromDecimalNumber"); + STAssertEquals([result length], + [testPlaces unsignedIntegerValue], + @"returned string to wrong number of places. Should be = %i Was = %i", + [testPlaces intValue], + [result length]); + // assert correct hex representation + STAssertTrueNoThrow([result isEqualToString:@"008769"], @"result was = %@ should be = @008769", result); +} + +- (void)testUnsignedRationalToString +{ + NSString* result = nil; + NSNumber* numerator = @1; + NSNumber* denominator = @10; + + result = [testHeaderWriter formatRationalWithNumerator:numerator + withDenominator:denominator + asSigned:FALSE]; + NSLog(@"%@", result); + STAssertNotNil(result, @"nil returned from testUnsignedRationalToString"); + STAssertTrueNoThrow([result length] == 16, @"returned string with wrong length. Exif rationals are 8 bytes, string has %ld bytes", [result length] / 2); + STAssertTrueNoThrow([result isEqualToString:@"000000010000000a"], @"result was = %@ should be = @0000000100000010", result); +} + +- (void)testSignedRationalToString +{ + NSString* result = nil; + NSNumber* numerator = @ - 1; + NSNumber* denominator = @ - 10; + + result = [testHeaderWriter formatRationalWithNumerator:numerator + withDenominator:denominator + asSigned:TRUE]; + NSLog(@"%@", result); + STAssertNotNil(result, @"nil returned from testSignedRationalToString"); + STAssertTrueNoThrow([result length] == 16, @"returned string with wrong length. Exif rationals are 8 bytes, string has %ld bytes", [result length] / 2); + STAssertTrueNoThrow([result isEqualToString:@"fffffffffffffff6"], @"result was = %@ should be = @000000FF000000F6", result); +} + +@end http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/0561c6ba/CordovaLibTests/CordovaTests.xcodeproj/project.pbxproj ---------------------------------------------------------------------- diff --git a/CordovaLibTests/CordovaTests.xcodeproj/project.pbxproj b/CordovaLibTests/CordovaTests.xcodeproj/project.pbxproj index 220d189..3ac6c85 100644 --- a/CordovaLibTests/CordovaTests.xcodeproj/project.pbxproj +++ b/CordovaLibTests/CordovaTests.xcodeproj/project.pbxproj @@ -42,6 +42,7 @@ 68A32D7D141030E4006B237C /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 686357AE141002F100DF4CF2 /* CoreGraphics.framework */; }; 68A32D7E141030EB006B237C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 686357AA141002F100DF4CF2 /* UIKit.framework */; }; 68A32D7F141030F3006B237C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 686357AC141002F100DF4CF2 /* Foundation.framework */; }; + 7E13A295175D487B00E522AB /* CDVExifTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E13A294175D487B00E522AB /* CDVExifTests.m */; }; 8220B5C216D541BD00EC3921 /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8220B5C116D541BD00EC3921 /* AssetsLibrary.framework */; }; 8220B5C616D542F500EC3921 /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8220B5C116D541BD00EC3921 /* AssetsLibrary.framework */; }; EB3B34E9161B5532003DBE7D /* libCordova.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EB3B34E6161B5454003DBE7D /* libCordova.a */; }; @@ -107,6 +108,8 @@ 686357D414100AF200DF4CF2 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; 686357DC14100B1600DF4CF2 /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; }; 68A32D7414103017006B237C /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; }; + 7E13A293175D487B00E522AB /* CDVExifTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDVExifTests.h; sourceTree = "<group>"; }; + 7E13A294175D487B00E522AB /* CDVExifTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVExifTests.m; sourceTree = "<group>"; }; 8220B5C116D541BD00EC3921 /* AssetsLibrary.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AssetsLibrary.framework; path = System/Library/Frameworks/AssetsLibrary.framework; sourceTree = SDKROOT; }; EB37018115D18B2D00BEBC43 /* CordovaLib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = CordovaLib.xcodeproj; path = ../CordovaLib/CordovaLib.xcodeproj; sourceTree = "<group>"; }; EB89634915FE66EA00E12277 /* CDVInvokedUrlCommandTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVInvokedUrlCommandTests.m; sourceTree = "<group>"; }; @@ -247,6 +250,8 @@ EB3B34F4161B585D003DBE7D /* CordovaLibTests */ = { isa = PBXGroup; children = ( + 7E13A293175D487B00E522AB /* CDVExifTests.h */, + 7E13A294175D487B00E522AB /* CDVExifTests.m */, EB96677116ADBCF500D86CDF /* CDVUserAgentTest.m */, EBA3554415A731F100F4DE24 /* CDVFakeFileManager.h */, EBA3554515A731F100F4DE24 /* CDVFakeFileManager.m */, @@ -429,6 +434,7 @@ EBA3556F15ABD0C900F4DE24 /* CDVFileTransferTests.m in Sources */, EB89634A15FE66EA00E12277 /* CDVInvokedUrlCommandTests.m in Sources */, EB96677216ADBCF500D86CDF /* CDVUserAgentTest.m in Sources */, + 7E13A295175D487B00E522AB /* CDVExifTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/0561c6ba/CordovaLibTests/ExifTests.h ---------------------------------------------------------------------- diff --git a/CordovaLibTests/ExifTests.h b/CordovaLibTests/ExifTests.h deleted file mode 100644 index 45e17c4..0000000 --- a/CordovaLibTests/ExifTests.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import <SenTestingKit/SenTestingKit.h> - -#import "../ExifTest/CDVJpegHeaderWriter.h" - -#define ARC4RANDOM_MAX 0x100000000 - -@interface ExifTestTests : SenTestCase { - CDVJpegHeaderWriter* testHeaderWriter; - NSNumber* testErrorThreshhold; -} - -- (void)testContinuedFractionWithUInt; -- (void)testContinuedFractionWithUFloat; -- (void)testContinuedFractionsWorstCase; -- (void)testFormatHexFromDecimal; -- (void)testFormatNumberWithLeadingZeroes; -- (void)testUnsignedRationalToString; -- (void)testSignedRationalToString; -@end http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/0561c6ba/CordovaLibTests/ExifTests.m ---------------------------------------------------------------------- diff --git a/CordovaLibTests/ExifTests.m b/CordovaLibTests/ExifTests.m deleted file mode 100644 index dfd6da4..0000000 --- a/CordovaLibTests/ExifTests.m +++ /dev/null @@ -1,172 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import <SenTestingKit/SenTestingKit.h> - -#import "ExifTestTests.h" -#import "../ExifTest/CDVJpegHeaderWriter.m" - -@implementation ExifTestTests - -- (void)setUp -{ - [super setUp]; - testHeaderWriter = [[CDVJpegHeaderWriter alloc] init]; - testErrorThreshhold = [NSNumber numberWithDouble:0.000001]; - NSLog(@"%x", ~10 + 1); -} - -- (void)tearDown -{ - // Tear-down code here. - - [super tearDown]; -} - -// ================================================================================================== -// rational approximation of decimal by continued fraction tests -// ================================================================================================== - -// tests continued fraction with random int -- (void)testContinuedFractionWithUInt -{ - NSLog(@"Continued Fraction Test with random int value, numerator should be generated value, denominator should be 1"); - NSNumber* numerator = @0; - NSNumber* denominator = @0; - NSNumber* testValue = [NSNumber numberWithInt:abs(arc4random())]; - [testHeaderWriter decimalToUnsignedRational:testValue - withResultNumerator:&numerator - withResultDenominator:&denominator]; - STAssertEquals([numerator intValue], - [testValue intValue], - @"Numerator did not match"); - STAssertEquals([denominator intValue], - 1, - @"denominator was not one"); -} - -// tests continued fraction with random float -- (void)testContinuedFractionWithUFloat -{ - NSLog(@"Continued Fraction Test with random double value, resulting fraction should be within acceptable error threshhold"); - NSNumber* threshhold = @0.1; - NSNumber* numerator = @0; - NSNumber* denominator = @0; - NSLog(@"%f", ((double)arc4random() / ARC4RANDOM_MAX) * 100.0f); - NSNumber* testValue = [NSNumber numberWithDouble: - ((double)arc4random() / ARC4RANDOM_MAX) * 100.0f]; - - [testHeaderWriter decimalToUnsignedRational:testValue - withResultNumerator:&numerator - withResultDenominator:&denominator]; - NSLog(@"%lf, %lf", [testValue doubleValue], [numerator doubleValue] / [denominator doubleValue]); - - STAssertEqualsWithAccuracy([testValue doubleValue], - [numerator doubleValue] / [denominator doubleValue], - [threshhold doubleValue], - @"rational approximation did not meet acceptable error threshhold"); -} - -// tests continued fraction in sqrt(2) worst case -- (void)testContinuedFractionsWorstCase -{ - NSLog(@"Continued Fraction Test with provable worst case ~sqrt(2), resulting fraction should be within acceptable error threshhold"); - NSNumber* threshhold = @0.1; - NSNumber* numerator = @0; - NSNumber* denominator = @0; - NSNumber* testValue = [NSNumber numberWithDouble:sqrt(2)]; - [testHeaderWriter decimalToUnsignedRational:testValue - withResultNumerator:&numerator - withResultDenominator:&denominator]; - STAssertEqualsWithAccuracy([testValue doubleValue], - [numerator doubleValue] / [denominator doubleValue], - [threshhold doubleValue], - @"rational approximation did not meet acceptable error threshhold"); -} - -// tests format hex from a decimal -- (void)testFormatHexFromDecimal -{ - NSNumber* testValue = @1; - NSNumber* testPlaces = @8; - NSString* result = nil; - - result = [testHeaderWriter formattedHexStringFromDecimalNumber:testValue - withPlaces:testPlaces]; - // assert not nil - STAssertNotNil(result, @"nil renturned from formattedHexStringFromDecimalNumber"); - // assert correct number of places - STAssertEquals([result length], [testPlaces unsignedIntegerValue], - @"returned string to wrong number of places. Should be = %i Was = %i", - [testPlaces intValue], - [result length]); - // assert correct hex representation - STAssertTrueNoThrow([result isEqualToString:@"00000001"], @"result should be equal to @00000001"); -} - -// tests format number string with leading zeroes -- (void)testFormatNumberWithLeadingZeroes -{ - NSString* result = nil; - NSNumber* testValue = @8769; // Exif SubIFD Offset Tag - NSNumber* testPlaces = @6; - - result = [testHeaderWriter formatNumberWithLeadingZeroes:testValue - withPlaces:testPlaces]; - STAssertNotNil(result, @"nil renturned from formattedHexStringFromDecimalNumber"); - STAssertEquals([result length], - [testPlaces unsignedIntegerValue], - @"returned string to wrong number of places. Should be = %i Was = %i", - [testPlaces intValue], - [result length]); - // assert correct hex representation - STAssertTrueNoThrow([result isEqualToString:@"008769"], @"result was = %@ should be = @008769", result); -} - -- (void)testUnsignedRationalToString -{ - NSString* result = nil; - NSNumber* numerator = @1; - NSNumber* denominator = @10; - - result = [testHeaderWriter formatRationalWithNumerator:numerator - withDenominator:denominator - asSigned:FALSE]; - NSLog(result); - STAssertNotNil(result, @"nil returned from testUnsignedRationalToString"); - STAssertTrueNoThrow([result length] == 16, @"returned string with wrong length. Exif rationals are 8 bytes, string has %ld bytes", [result length] / 2); - STAssertTrueNoThrow([result isEqualToString:@"000000010000000a"], @"result was = %@ should be = @0000000100000010", result); -} - -- (void)testSignedRationalToString -{ - NSString* result = nil; - NSNumber* numerator = @ - 1; - NSNumber* denominator = @ - 10; - - result = [testHeaderWriter formatRationalWithNumerator:numerator - withDenominator:denominator - asSigned:TRUE]; - NSLog(result); - STAssertNotNil(result, @"nil returned from testSignedRationalToString"); - STAssertTrueNoThrow([result length] == 16, @"returned string with wrong length. Exif rationals are 8 bytes, string has %ld bytes", [result length] / 2); - STAssertTrueNoThrow([result isEqualToString:@"fffffffffffffff6"], @"result was = %@ should be = @000000FF000000F6", result); -} - -@end
