You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2013/03/23 01:05:15 UTC
[05/13] ios commit: [CB-1285] added unit tests for
CDVJpegHeaderWriter,
tests rational approximation and utility functions involved in the creation of
the APP1 data block in a JPEG header. For test of APP1 data block integrity,
best method is to read res
[CB-1285] added unit tests for CDVJpegHeaderWriter, tests rational approximation and utility functions involved in the creation of the APP1 data block in a JPEG header. For test of APP1 data block integrity, best method is to read resulting image
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/c9601517
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/c9601517
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/c9601517
Branch: refs/heads/master
Commit: c960151767abfe000e007278d59a70512861fb01
Parents: fbebe8f
Author: lorinbeer <lo...@adobe.com>
Authored: Wed Mar 20 21:41:42 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Wed Mar 20 21:41:42 2013 -0700
----------------------------------------------------------------------
CordovaLibTests/ExifTests.h | 27 +++++++
CordovaLibTests/ExifTests.m | 155 ++++++++++++++++++++++++++++++++++++++
2 files changed, 182 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c9601517/CordovaLibTests/ExifTests.h
----------------------------------------------------------------------
diff --git a/CordovaLibTests/ExifTests.h b/CordovaLibTests/ExifTests.h
new file mode 100644
index 0000000..b46241b
--- /dev/null
+++ b/CordovaLibTests/ExifTests.h
@@ -0,0 +1,27 @@
+//
+// ExifTestTests.h
+// ExifTestTests
+//
+// Created by Lorin Beer on 2013-03-18.
+//
+//
+
+#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
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c9601517/CordovaLibTests/ExifTests.m
----------------------------------------------------------------------
diff --git a/CordovaLibTests/ExifTests.m b/CordovaLibTests/ExifTests.m
new file mode 100644
index 0000000..960ac95
--- /dev/null
+++ b/CordovaLibTests/ExifTests.m
@@ -0,0 +1,155 @@
+//
+// ExifTestTests.m
+// ExifTestTests
+//
+// Created by Lorin Beer on 2013-03-18.
+//
+//
+
+#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