Skip to content

Commit

Permalink
수정사항
Browse files Browse the repository at this point in the history
 - 유닛테스트 추가
 - 버그수정
  • Loading branch information
HanweeeeLee committed Oct 13, 2020
1 parent 014f3cf commit b68f6fc
Show file tree
Hide file tree
Showing 8 changed files with 335 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

/* Begin PBXBuildFile section */
78CE30692534674E0020E536 /* FlexibleModelProtocol.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78CE305F2534674E0020E536 /* FlexibleModelProtocol.framework */; };
78CE306E2534674E0020E536 /* FlexibleModelProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78CE306D2534674E0020E536 /* FlexibleModelProtocolTests.swift */; };
78CE30702534674E0020E536 /* FlexibleModelProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 78CE30622534674E0020E536 /* FlexibleModelProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
78CE307C2534677E0020E536 /* FlexibleModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78CE307B2534677E0020E536 /* FlexibleModelProtocol.swift */; };
78D95D7D2535B0FB009A379F /* HWXMLEelement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78D95D7B2535B0FB009A379F /* HWXMLEelement.swift */; };
78D95D7E2535B0FB009A379F /* HWXMLParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78D95D7C2535B0FB009A379F /* HWXMLParser.swift */; };
78D95D842535B5C9009A379F /* FromTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78D95D832535B5C9009A379F /* FromTest.swift */; };
78D95D882535B5D4009A379F /* ToTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78D95D872535B5D4009A379F /* ToTest.swift */; };
78D95D9F2535D7C2009A379F /* TestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78D95D9C2535D7C2009A379F /* TestModel.swift */; };
78D95DA02535D7C2009A379F /* SampleXML.xml in Resources */ = {isa = PBXBuildFile; fileRef = 78D95D9D2535D7C2009A379F /* SampleXML.xml */; };
78D95DA12535D7C2009A379F /* SampleJson.json in Resources */ = {isa = PBXBuildFile; fileRef = 78D95D9E2535D7C2009A379F /* SampleJson.json */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -30,11 +34,15 @@
78CE30622534674E0020E536 /* FlexibleModelProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FlexibleModelProtocol.h; sourceTree = "<group>"; };
78CE30632534674E0020E536 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
78CE30682534674E0020E536 /* FlexibleModelProtocolTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FlexibleModelProtocolTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
78CE306D2534674E0020E536 /* FlexibleModelProtocolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlexibleModelProtocolTests.swift; sourceTree = "<group>"; };
78CE306F2534674E0020E536 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
78CE307B2534677E0020E536 /* FlexibleModelProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlexibleModelProtocol.swift; sourceTree = "<group>"; };
78D95D7B2535B0FB009A379F /* HWXMLEelement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HWXMLEelement.swift; sourceTree = "<group>"; };
78D95D7C2535B0FB009A379F /* HWXMLParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HWXMLParser.swift; sourceTree = "<group>"; };
78D95D832535B5C9009A379F /* FromTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FromTest.swift; sourceTree = "<group>"; };
78D95D872535B5D4009A379F /* ToTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToTest.swift; sourceTree = "<group>"; };
78D95D9C2535D7C2009A379F /* TestModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestModel.swift; sourceTree = "<group>"; };
78D95D9D2535D7C2009A379F /* SampleXML.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = SampleXML.xml; sourceTree = "<group>"; };
78D95D9E2535D7C2009A379F /* SampleJson.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SampleJson.json; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -89,12 +97,24 @@
78CE306C2534674E0020E536 /* FlexibleModelProtocolTests */ = {
isa = PBXGroup;
children = (
78CE306D2534674E0020E536 /* FlexibleModelProtocolTests.swift */,
78D95D9B2535D7C2009A379F /* Mock */,
78CE306F2534674E0020E536 /* Info.plist */,
78D95D832535B5C9009A379F /* FromTest.swift */,
78D95D872535B5D4009A379F /* ToTest.swift */,
);
path = FlexibleModelProtocolTests;
sourceTree = "<group>";
};
78D95D9B2535D7C2009A379F /* Mock */ = {
isa = PBXGroup;
children = (
78D95D9C2535D7C2009A379F /* TestModel.swift */,
78D95D9D2535D7C2009A379F /* SampleXML.xml */,
78D95D9E2535D7C2009A379F /* SampleJson.json */,
);
path = Mock;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -194,6 +214,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
78D95DA02535D7C2009A379F /* SampleXML.xml in Resources */,
78D95DA12535D7C2009A379F /* SampleJson.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -214,7 +236,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
78CE306E2534674E0020E536 /* FlexibleModelProtocolTests.swift in Sources */,
78D95D9F2535D7C2009A379F /* TestModel.swift in Sources */,
78D95D882535B5D4009A379F /* ToTest.swift in Sources */,
78D95D842535B5C9009A379F /* FromTest.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ protocol FlexibleModelProtocol:Codable,Equatable {
static func fromNSDictionary<T:FlexibleModelProtocol>(nsDictionary:NSDictionary,object:T) -> T?

func toJson() -> String
func toXML() -> String
func toDictionary() -> Dictionary<String,Any>
func toNSDictionary() -> NSDictionary
func toXML() -> String?
func toDictionary() -> Dictionary<String,Any>?
func toNSDictionary() -> NSDictionary?

}

Expand Down Expand Up @@ -84,9 +84,13 @@ extension FlexibleModelProtocol {
}

func toXML() -> String? {
let dic = toDictionary()
let parser:HWXMLParser = HWXMLParser()
return parser.toXMLString(dictionary: dic)
var returnValue:String? = nil
if let dic = toDictionary() {
let parser:HWXMLParser = HWXMLParser()
returnValue = parser.toXMLString(dictionary: dic)
}

return returnValue
}

func toDictionary() -> Dictionary<String,Any>? {
Expand All @@ -103,7 +107,11 @@ extension FlexibleModelProtocol {
}

func toNSDictionary() -> NSDictionary? {
return self.toDictionary() as NSDictionary
var returnValue:NSDictionary? = nil
if let dic = self.toDictionary() {
returnValue = dic as NSDictionary
}
return returnValue
}

}
Expand Down

This file was deleted.

85 changes: 85 additions & 0 deletions FlexibleModelProtocol/FlexibleModelProtocolTests/FromTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// FromTest.swift
// FlexibleModelProtocolTests
//
// Created by hanwe on 2020/10/13.
//

import UIKit
import XCTest
@testable import FlexibleModelProtocol

class FromTest: XCTestCase {
override func setUpWithError() throws {

}

override func tearDownWithError() throws {

}

func testFromJson() {
if let path = Bundle(for: type(of: self)).path(forResource: "SampleJson", ofType: "json") {
do {
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
if let myModel:MyModel = MyModel.fromJson(jsonData: data, object: MyModel()) {
let mainModel = myModel.lostArticleBizInfo
if mainModel.list_total_count == "" {
XCTAssertTrue(false)
}
if mainModel.result.code == "" {
XCTAssertTrue(false)
}
if mainModel.result.message == "" {
XCTAssertTrue(false)
}
if mainModel.row.isEmpty {
XCTAssertTrue(false)
}
XCTAssertTrue(true)
}
else {
XCTAssertTrue(false)
}
} catch {
XCTAssertTrue(false)
}
}
else {
XCTAssertTrue(false)
}
}

func testFromXml() {
if let path = Bundle(for: type(of: self)).path(forResource: "SampleXML", ofType: "xml") {
do {
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
if let myModel:MyModel = MyModel.fromXML(xmlData: data, object: MyModel()) {
let mainModel = myModel.lostArticleBizInfo
if mainModel.list_total_count == "" {
XCTAssertTrue(false)
}
if mainModel.result.code == "" {
XCTAssertTrue(false)
}
if mainModel.result.message == "" {
XCTAssertTrue(false)
}
if mainModel.row.isEmpty {
XCTAssertTrue(false)
}
XCTAssertTrue(true)
}
else {
XCTAssertTrue(false)
}
} catch {
XCTAssertTrue(false)
}
}
else {
XCTAssertTrue(false)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"lostArticleBizInfo": {
"list_total_count": "234",
"result": {
"code": "INFO-000",
"message": "Success"
},
"row": [
{
"idx": "580",
"code": "t1",
"location": "new york",
"company": "Coach"
},
{
"idx": "520",
"code": "b2",
"location": "san francisco",
"company": "Facebook"
},
{
"idx": "521",
"code": "b2",
"location": "paris",
"company": "Sandro"
},
{
"idx": "588",
"code": "t1",
"location": "seoul",
"company": "Samsung"
},
{
"idx": "589",
"code": "t1",
"location": "cupertino",
"company": "Apple"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>
<lostArticleBizInfo>
<list_total_count>234</list_total_count>
<result>
<code>INFO-000</code>
<message>Success</message>
</result>
<row>
<idx>580</idx>
<code>t1</code>
<location>new york</location>
<company>Coach</company>
</row>
<row>
<idx>520</idx>
<code>b2</code>
<location>san francisco</location>
<company>Facebook</company>
</row>
<row>
<idx>521</idx>
<code>b2</code>
<location>paris</location>
<company>Sandro</company>
</row>
<row>
<idx>588</idx>
<code>t1</code>
<location>seoul</location>
<company>Samsung</company>
</row>
<row>
<idx>589</idx>
<code>t1</code>
<location>cupertino</location>
<company>Apple</company>
</row>
</lostArticleBizInfo>

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// TestModel.swift
// FlexibleModelProtocolTests
//
// Created by hanwe on 2020/10/13.
//
@testable import FlexibleModelProtocol
import Foundation


struct MyModel: FlexibleModelProtocol {
var lostArticleBizInfo:MySubModel = MySubModel()
}
struct MySubModel: FlexibleModelProtocol {
var list_total_count:String = ""
var result:MyResultModel = MyResultModel()
var row:Array<MyRowModel> = Array()
}

struct MyResultModel: FlexibleModelProtocol {
var code:String = ""
var message:String = ""
}

struct MyRowModel: FlexibleModelProtocol {
var idx:String = ""
var code:String = ""
var location:String = ""
var company:String = ""
}


Loading

0 comments on commit b68f6fc

Please sign in to comment.