Skip to content

Commit c9c96af

Browse files
committed
Adding a unit test that should fail right now
(if I could get Xcode to **actually** run the tests instead of only showing green checkmarks, that is)
1 parent cf2559d commit c9c96af

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

UnitTests/SPParserUtilsTest.m

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//
2+
// SPParserUtilsTest.m
3+
// sequel-pro
4+
//
5+
// Created by Max Lohrmann on 27.01.15.
6+
// Copyright (c) 2015 Max Lohrmann. All rights reserved.
7+
//
8+
// Permission is hereby granted, free of charge, to any person
9+
// obtaining a copy of this software and associated documentation
10+
// files (the "Software"), to deal in the Software without
11+
// restriction, including without limitation the rights to use,
12+
// copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the
14+
// Software is furnished to do so, subject to the following
15+
// conditions:
16+
//
17+
// The above copyright notice and this permission notice shall be
18+
// included in all copies or substantial portions of the Software.
19+
//
20+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27+
// OTHER DEALINGS IN THE SOFTWARE.
28+
//
29+
// More info at <https://github.com/sequelpro/sequelpro>
30+
31+
#define USE_APPLICATION_UNIT_TEST 1
32+
33+
#import <Cocoa/Cocoa.h>
34+
#import <SenTestingKit/SenTestingKit.h>
35+
36+
#include "SPParserUtils.h"
37+
38+
@interface SPParserUtilsTest : SenTestCase
39+
40+
- (void)testUtf8strlen;
41+
42+
@end
43+
44+
@implementation SPParserUtilsTest
45+
46+
- (void)testUtf8strlen {
47+
const char *empty = "";
48+
NSString *emptyString = [NSString stringWithCString:empty encoding:NSUTF8StringEncoding];
49+
STAssertEquals(utf8strlen(empty),[emptyString length], @"empty string");
50+
51+
const char *singleByteSeq = "Hello World!";
52+
NSString *singleByteString = [NSString stringWithCString:singleByteSeq encoding:NSUTF8StringEncoding];
53+
STAssertEquals(utf8strlen(singleByteSeq), [singleByteString length], @"ASCII UTF-8 subset");
54+
55+
const char *twoByteSeq = "H\xC3\xA4ll\xC3\xB6 W\xC3\x9Crld\xC3\x9F!"; // Hällö WÜrldß!
56+
NSString *twoByteString = [NSString stringWithCString:twoByteSeq encoding:NSUTF8StringEncoding];
57+
STAssertEquals(utf8strlen(twoByteSeq), [twoByteString length], @"String containing two-byte utf8 characters");
58+
59+
const char *threeByteSeq = "\xE3\x81\x93.\xE3\x82\x93.\xE3\x81\xAB.\xE3\x81\xA1.\xE3\x81\xAF"; // こ.ん.に.ち.は
60+
NSString *threeByteString = [NSString stringWithCString:threeByteSeq encoding:NSUTF8StringEncoding];
61+
STAssertEquals(utf8strlen(threeByteSeq), [threeByteString length], @"String containing three-byte utf8 characters");
62+
63+
const char *fourByteSeq = "\xF0\x9F\x8D\x8F\xF0\x9F\x8D\x8B\xF0\x9F\x8D\x92"; //🍏🍋🍒
64+
NSString *fourByteString = [NSString stringWithCString:fourByteSeq encoding:NSUTF8StringEncoding];
65+
STAssertEquals(utf8strlen(fourByteSeq), [fourByteString length], @"String containing only 4-byte utf8 characters (outside BMP)");
66+
67+
const char *mixedSeq = "\xE3\x81\x82\xE3\x82\x81\xE3\x80\x90\xE9\xA3\xB4\xE3\x80\x91\xF0\x9F\x8D\xAD \xE2\x89\x88 S\xC3\xBC\xC3\x9Figkeit"; // あめ【飴】🍭 ≈ Süßigkeit
68+
NSString *mixedString = [NSString stringWithCString:mixedSeq encoding:NSUTF8StringEncoding];
69+
STAssertEquals(utf8strlen(mixedSeq), [mixedString length], @"utf8 characters with all 4 lengths mixed together.");
70+
}
71+
72+
@end

sequel-pro.xcodeproj/project.pbxproj

+14
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@
184184
50D3C3491A75B8A800B5429C /* GotoDatabaseDialog.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50D3C34B1A75B8A800B5429C /* GotoDatabaseDialog.xib */; };
185185
50D3C3521A77135F00B5429C /* SPParserUtils.c in Sources */ = {isa = PBXBuildFile; fileRef = 50D3C3501A77135F00B5429C /* SPParserUtils.c */; };
186186
50D3C3541A7715E600B5429C /* SPParserUtils.c in Sources */ = {isa = PBXBuildFile; fileRef = 50D3C3501A77135F00B5429C /* SPParserUtils.c */; };
187+
50D3C35C1A771C4C00B5429C /* SPParserUtilsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50D3C35B1A771C4C00B5429C /* SPParserUtilsTest.m */; };
188+
50D3C35D1A77217800B5429C /* SPParserUtils.c in Sources */ = {isa = PBXBuildFile; fileRef = 50D3C3501A77135F00B5429C /* SPParserUtils.c */; };
187189
50E217B318174246009D3580 /* SPColorSelectorView.m in Sources */ = {isa = PBXBuildFile; fileRef = 50E217B218174246009D3580 /* SPColorSelectorView.m */; };
188190
50E217B618174280009D3580 /* SPFavoriteColorSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = 50E217B518174280009D3580 /* SPFavoriteColorSupport.m */; };
189191
5806B76411A991EC00813A88 /* SPDocumentController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5806B76311A991EC00813A88 /* SPDocumentController.m */; };
@@ -891,6 +893,7 @@
891893
50D3C34A1A75B8A800B5429C /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/GotoDatabaseDialog.xib; sourceTree = "<group>"; };
892894
50D3C3501A77135F00B5429C /* SPParserUtils.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SPParserUtils.c; sourceTree = "<group>"; };
893895
50D3C3511A77135F00B5429C /* SPParserUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPParserUtils.h; sourceTree = "<group>"; };
896+
50D3C35B1A771C4C00B5429C /* SPParserUtilsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPParserUtilsTest.m; sourceTree = "<group>"; };
894897
50E217B118174246009D3580 /* SPColorSelectorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPColorSelectorView.h; sourceTree = "<group>"; };
895898
50E217B218174246009D3580 /* SPColorSelectorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPColorSelectorView.m; sourceTree = "<group>"; };
896899
50E217B418174280009D3580 /* SPFavoriteColorSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPFavoriteColorSupport.h; sourceTree = "<group>"; };
@@ -2345,13 +2348,22 @@
23452348
380F4EF20FC0B67A00B0BFD7 /* Unit Tests */ = {
23462349
isa = PBXGroup;
23472350
children = (
2351+
50D3C3591A771C2300B5429C /* Other */,
23482352
1198F5B41174EDDE00670590 /* Database Actions */,
23492353
17DC886A126B378A00E9AAEC /* Category Additions */,
23502354
);
23512355
name = "Unit Tests";
23522356
path = UnitTests;
23532357
sourceTree = "<group>";
23542358
};
2359+
50D3C3591A771C2300B5429C /* Other */ = {
2360+
isa = PBXGroup;
2361+
children = (
2362+
50D3C35B1A771C4C00B5429C /* SPParserUtilsTest.m */,
2363+
);
2364+
name = Other;
2365+
sourceTree = "<group>";
2366+
};
23552367
583CE39511722B70008F148E /* File Compression */ = {
23562368
isa = PBXGroup;
23572369
children = (
@@ -3027,13 +3039,15 @@
30273039
isa = PBXSourcesBuildPhase;
30283040
buildActionMask = 2147483647;
30293041
files = (
3042+
50D3C35D1A77217800B5429C /* SPParserUtils.c in Sources */,
30303043
380F4EF50FC0B68F00B0BFD7 /* SPStringAdditionsTests.m in Sources */,
30313044
1760599F1336199D0098E162 /* SPMenuAdditionsTests.m in Sources */,
30323045
1798F1C4155018E2004B0AB8 /* SPMutableArrayAdditionsTests.m in Sources */,
30333046
17DB5F441555CA300046834B /* SPMutableArrayAdditions.m in Sources */,
30343047
17DB5F4A1555CA810046834B /* SPMenuAdditions.m in Sources */,
30353048
1717F9661557E0450065C036 /* SPStringAdditions.m in Sources */,
30363049
1717FA401558313A0065C036 /* RegexKitLite.m in Sources */,
3050+
50D3C35C1A771C4C00B5429C /* SPParserUtilsTest.m in Sources */,
30373051
);
30383052
runOnlyForDeploymentPostprocessing = 0;
30393053
};

0 commit comments

Comments
 (0)