Skip to content

Instantly share code, notes, and snippets.

@veader
Last active August 29, 2015 13:56
Show Gist options
  • Save veader/9102508 to your computer and use it in GitHub Desktop.
Save veader/9102508 to your computer and use it in GitHub Desktop.
- (void)testShouldDecodeBase64EncodedString {
NSString *encodedString = @"ZEdWemRBPT0=";
NSString *decodedString = [[NSString stringWithBase64EncodedString:encodedString] base64DecodedString];
NSString *properResult = @"test";
XCTAssert([properResult isEqualToString:decodedString], @"Unable to decode base64 encoded string");
}
- (void)testShouldWorkWithoutCategoryToDecodeUTF8String {
NSString *encodedString = @"dTA0QTA6INKgINKhINKiINKjINKkINKlINKmINKnINKoINKpINKqINKrINKsINKtINKuINKvINKwINKxINKyINKzINK0INK1INK2INK3INK4INK5INK6INK7INK8INK9INK+INK/";
NSData *encodedData = [[NSData alloc] initWithBase64Encoding:encodedString];
NSString *decodedString = [[NSString alloc] initWithData:encodedData encoding:NSUTF8StringEncoding];
NSString *properResult = @"u04A0: Ҡ ҡ Ң ң Ҥ ҥ Ҧ ҧ Ҩ ҩ Ҫ ҫ Ҭ ҭ Ү ү Ұ ұ Ҳ ҳ Ҵ ҵ Ҷ ҷ Ҹ ҹ Һ һ Ҽ ҽ Ҿ ҿ";
XCTAssert([properResult isEqualToString:decodedString], @"Unable to decode base64 encoded UTF8 string");
}
- (void)testShouldDecodeBase64EncodedUTF8String {
NSString *encodedString = @"dTA0QTA6INKgINKhINKiINKjINKkINKlINKmINKnINKoINKpINKqINKrINKsINKtINKuINKvINKwINKxINKyINKzINK0INK1INK2INK3INK4INK5INK6INK7INK8INK9INK+INK/";
NSString *decodedString = [[NSString stringWithBase64EncodedString:encodedString] base64DecodedString];
NSString *properResult = @"u04A0: Ҡ ҡ Ң ң Ҥ ҥ Ҧ ҧ Ҩ ҩ Ҫ ҫ Ҭ ҭ Ү ү Ұ ұ Ҳ ҳ Ҵ ҵ Ҷ ҷ Ҹ ҹ Һ һ Ҽ ҽ Ҿ ҿ";
XCTAssert([properResult isEqualToString:decodedString], @"Unable to decode base64 encoded UTF8 string");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment