Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Extensions/XEP-0054/XMPPvCardTemp.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extern NSString *const kXMPPvCardTempElement;

@property (nonatomic, strong, nullable) NSArray<XMPPvCardTempAdr*> *addresses;
@property (nonatomic, strong, nullable) NSArray<XMPPvCardTempLabel*> *labels;
@property (nonatomic, strong, nullable) NSArray<XMPPvCardTempTel*> *telecomsAddresses;
@property (nonatomic, strong) NSArray<XMPPvCardTempTel*> *telecomsAddresses;
@property (nonatomic, strong) NSArray<XMPPvCardTempEmail*> *emailAddresses;

@property (nonatomic, strong, nullable) XMPPJID *jid;
Expand Down
44 changes: 39 additions & 5 deletions Extensions/XEP-0054/XMPPvCardTemp.m
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,45 @@ - (void)setLabels:(NSArray *)labels { }
- (void)clearLabels { }


- (NSArray *)telecomsAddresses { return nil; }
- (void)addTelecomsAddress:(XMPPvCardTempTel *)tel { }
- (void)removeTelecomsAddress:(XMPPvCardTempTel *)tel { }
- (void)setTelecomsAddresses:(NSArray *)tels { }
- (void)clearTelecomsAddresses { }
- (NSArray *)telecomsAddresses {
NSMutableArray *result = [NSMutableArray new];
NSArray *tels = [self elementsForName:@"TEL"];
for (NSXMLElement *tel in tels) {
XMPPvCardTempTel *vCardTempTel = [XMPPvCardTempTel vCardTelFromElement:tel];
[result addObject:vCardTempTel];
}

return result;
}


- (void)addTelecomsAddress:(XMPPvCardTempTel *)tel {
[self addChild:tel];
}


- (void)removeTelecomsAddress:(XMPPvCardTempTel *)tel {
NSArray *telElements = [self elementsForName:@"TEL"];
for (NSXMLElement *element in telElements) {
XMPPvCardTempTel *vCardTempTel = [XMPPvCardTempTel vCardTelFromElement:[element copy]];
if ([vCardTempTel.number isEqualToString:tel.number]) {
NSUInteger index = [[self children] indexOfObject:element];
[self removeChildAtIndex:index];
}
}
}

- (void)setTelecomsAddresses:(NSArray<XMPPvCardTempTel *> *)tels {
[self clearTelecomsAddresses];
for (XMPPvCardTempTel *tel in tels) {
[self addTelecomsAddress:tel];
}
}


- (void)clearTelecomsAddresses {
[self removeElementsForName:@"TEL"];
}


- (NSArray *)emailAddresses {
Expand Down
2 changes: 1 addition & 1 deletion Extensions/XEP-0054/XMPPvCardTempEmail.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ - (NSString *)userid {
}


- (void)setIsUserid:(NSString *)userid {
- (void)setUserid:(NSString *)userid {
XMPP_VCARD_SET_STRING_CHILD(userid, @"USERID");
}

Expand Down
4 changes: 2 additions & 2 deletions Extensions/XEP-0054/XMPPvCardTempTel.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ - (BOOL)hasMessaging {
}


- (void)setIsMessaging:(BOOL)msg {
XMPP_VCARD_SET_EMPTY_CHILD(msg && ![self hasMessaging], @"MSG");
- (void)setHasMessaging:(BOOL)hasMessaging {
XMPP_VCARD_SET_EMPTY_CHILD(hasMessaging && ![self hasMessaging], @"MSG");
}


Expand Down
91 changes: 91 additions & 0 deletions Xcode/Testing-Swift/XMPPvCardTempTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// XMPPvCardTempTests.swift
// XMPPFrameworkSwiftTests
//
// Created by Oleg Langer on 07.04.20.
//

import XCTest

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import KissXML

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like I don't have to import anything at all.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, it's probably implicitly re-exported by XMPPFramework.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, hm that's weird that you don't even need to import XMPPFramework.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I also don't really understand why. :)

class XMPPvCardTempTests: XCTestCase {
var xmlString: String!
var sut: XMPPvCardTemp!

override func setUp() {
xmlString = """
<vCard xmlns="vcard-temp">
<NICKNAME>DESKTOP</NICKNAME>
<EMAIL>
<INTERNET/>
<USERID>[email protected]</USERID>
</EMAIL>
<TEL>
<WORK/>
<VOICE/>
<NUMBER>303-308-3282</NUMBER>
</TEL>
</vCard>
"""
let element = try! XMLElement(xmlString: xmlString)
sut = XMPPvCardTemp.vCardTemp(from: element)
}

func testCreateFromXMLString() {
XCTAssertNotNil(sut)
}

func testGetEmailAddress() {
XCTAssertEqual(sut.emailAddresses.count, 1)
let email = sut.emailAddresses.first
XCTAssertNotNil(email)
XCTAssertEqual(email?.userid, "[email protected]")
XCTAssertEqual(email?.isInternet, true)
}

func testRemoveEmailAddress() {
let email = sut.emailAddresses.first!
sut.removeEmailAddress(email)

XCTAssertEqual(sut.emailAddresses.count, 0)
}

func testAddEmailAddress() {
// Remove all first
sut.clearEmailAddresses()

let element = XMLElement(name: "EMAIL")
let newMail = XMPPvCardTempEmail.vCardEmail(from: element)
newMail.isWork = true
newMail.userid = "[email protected]"
sut.addEmailAddress(newMail)

XCTAssertEqual(sut.emailAddresses.first, newMail)
}

func testGetTelecomAddress() {
XCTAssertEqual(sut.telecomsAddresses.count, 1)
let tel = sut.telecomsAddresses.first!
XCTAssertTrue(tel.isWork)
XCTAssertTrue(tel.isVoice)
XCTAssertEqual(tel.number, "303-308-3282")
}

func testRemoveTelecomAddresses() {
let tel = sut.telecomsAddresses.first!
sut.removeTelecomsAddress(tel)
XCTAssertEqual(sut.telecomsAddresses.count, 0)
}

func testAddTelecomAddress() {
sut.clearTelecomsAddresses()

let element = XMLElement(name: "TEL")
let newTel = XMPPvCardTempTel.vCardTel(from: element)
newTel.isCell = true
newTel.number = "101"
sut.addTelecomsAddress(newTel)

XCTAssertEqual(sut.telecomsAddresses.count, 1)
XCTAssertEqual(sut.telecomsAddresses.first!, newTel)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
1A5DC58D2566E3FC0AAB5BA7 /* Pods_XMPPFrameworkSwiftTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6923171573DDCA8E2DEC3A22 /* Pods_XMPPFrameworkSwiftTests.framework */; };
9943D285243CA2EB000A9DFC /* XMPPvCardTempTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9943D284243CA2EB000A9DFC /* XMPPvCardTempTests.swift */; };
D945D6F71FD9EA2100C7502C /* XMPPPresenceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D945D6F61FD9EA2100C7502C /* XMPPPresenceTests.swift */; };
D973A07C1D2F18040096F3ED /* CapabilitiesHashingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D973A06F1D2F18040096F3ED /* CapabilitiesHashingTest.m */; };
D973A07D1D2F18040096F3ED /* EncodeDecodeTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D973A0701D2F18040096F3ED /* EncodeDecodeTest.m */; };
Expand Down Expand Up @@ -45,6 +46,7 @@
63F50D921C60208200CA0201 /* XMPPFrameworkTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = XMPPFrameworkTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
63F50D971C60208200CA0201 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6923171573DDCA8E2DEC3A22 /* Pods_XMPPFrameworkSwiftTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_XMPPFrameworkSwiftTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9943D284243CA2EB000A9DFC /* XMPPvCardTempTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = XMPPvCardTempTests.swift; path = "../../Testing-Swift/XMPPvCardTempTests.swift"; sourceTree = "<group>"; };
AE993B61B8D33F0468A9B133 /* Pods-XMPPFrameworkTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-XMPPFrameworkTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-XMPPFrameworkTests/Pods-XMPPFrameworkTests.release.xcconfig"; sourceTree = "<group>"; };
D945D6F61FD9EA2100C7502C /* XMPPPresenceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = XMPPPresenceTests.swift; path = "../../Testing-Swift/XMPPPresenceTests.swift"; sourceTree = "<group>"; };
D973A06E1D2F18030096F3ED /* XMPPFrameworkTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "XMPPFrameworkTests-Bridging-Header.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -173,6 +175,7 @@
D9B81AC61FBCD39E00455683 /* XMPPMockStream.h */,
D9B81AC51FBCD39E00455683 /* XMPPMockStream.m */,
D9A7B03F1FB988EC005183CD /* Info.plist */,
9943D284243CA2EB000A9DFC /* XMPPvCardTempTests.swift */,
);
path = XMPPFrameworkSwiftTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -411,6 +414,7 @@
buildActionMask = 2147483647;
files = (
D9B81AC91FBCD3B400455683 /* XMPPBookmarksModuleTests.swift in Sources */,
9943D285243CA2EB000A9DFC /* XMPPvCardTempTests.swift in Sources */,
D9B81AC71FBCD39E00455683 /* XMPPMockStream.m in Sources */,
D945D6F71FD9EA2100C7502C /* XMPPPresenceTests.swift in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
4A6D92D0C7C1950CBA77BE55 /* Pods_XMPPFrameworkTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23C81F1C22F160BD2130E79A /* Pods_XMPPFrameworkTests.framework */; };
9943D287243D0E17000A9DFC /* XMPPvCardTempTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9943D286243D0E17000A9DFC /* XMPPvCardTempTests.swift */; };
B407FF87953F6A78BCCE2871 /* Pods_XMPPFrameworkSwiftTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 777EEF98731B0EC5DBD49953 /* Pods_XMPPFrameworkSwiftTests.framework */; };
D93B87901FBCE8D6002B6CB7 /* XMPPBookmarksModuleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D93B878F1FBCE8D6002B6CB7 /* XMPPBookmarksModuleTests.swift */; };
D93B87931FBCE90D002B6CB7 /* XMPPMockStream.m in Sources */ = {isa = PBXBuildFile; fileRef = D93B87911FBCE90C002B6CB7 /* XMPPMockStream.m */; };
Expand Down Expand Up @@ -43,6 +44,7 @@
5AA422BDF36502C8A148D622 /* Pods-XMPPFrameworkTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-XMPPFrameworkTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-XMPPFrameworkTests/Pods-XMPPFrameworkTests.debug.xcconfig"; sourceTree = "<group>"; };
5CE125FD447C51125BCAAAFF /* Pods-XMPPFrameworkSwiftTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-XMPPFrameworkSwiftTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-XMPPFrameworkSwiftTests/Pods-XMPPFrameworkSwiftTests.debug.xcconfig"; sourceTree = "<group>"; };
777EEF98731B0EC5DBD49953 /* Pods_XMPPFrameworkSwiftTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_XMPPFrameworkSwiftTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9943D286243D0E17000A9DFC /* XMPPvCardTempTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = XMPPvCardTempTests.swift; path = "../../Testing-Swift/XMPPvCardTempTests.swift"; sourceTree = "<group>"; };
D93B878E1FBCE8D6002B6CB7 /* XMPPFrameworkTests-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "XMPPFrameworkTests-Bridging-Header.h"; path = "../../Testing-Swift/XMPPFrameworkTests-Bridging-Header.h"; sourceTree = "<group>"; };
D93B878F1FBCE8D6002B6CB7 /* XMPPBookmarksModuleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = XMPPBookmarksModuleTests.swift; path = "../../Testing-Swift/XMPPBookmarksModuleTests.swift"; sourceTree = "<group>"; };
D93B87911FBCE90C002B6CB7 /* XMPPMockStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPMockStream.m; path = "../../Testing-Shared/XMPPMockStream.m"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -164,6 +166,7 @@
D9A7B02E1FB985BE005183CD /* XMPPFrameworkSwiftTests */ = {
isa = PBXGroup;
children = (
9943D286243D0E17000A9DFC /* XMPPvCardTempTests.swift */,
D945D6F81FD9EA3B00C7502C /* XMPPPresenceTests.swift */,
D93B87921FBCE90D002B6CB7 /* XMPPMockStream.h */,
D93B87911FBCE90C002B6CB7 /* XMPPMockStream.m */,
Expand Down Expand Up @@ -405,6 +408,7 @@
buildActionMask = 2147483647;
files = (
D93B87931FBCE90D002B6CB7 /* XMPPMockStream.m in Sources */,
9943D287243D0E17000A9DFC /* XMPPvCardTempTests.swift in Sources */,
D93B87901FBCE8D6002B6CB7 /* XMPPBookmarksModuleTests.swift in Sources */,
D945D6F91FD9EA3C00C7502C /* XMPPPresenceTests.swift in Sources */,
);
Expand Down