-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pim.4dm
170 lines (134 loc) · 4.98 KB
/
test_pim.4dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//%attributes = {"invisible":true}
var $TEST_VALUE_UID : Text
$TEST_VALUE_UID:="69531f4a-c34d-4a1e-8922-bd38a9476a53"
var $testCard : Object
$testCard:=PIM.VCard.new()
$testCard.version:="3.0"
$testCard.uid:=$TEST_VALUE_UID
$testCard.lastName:="Doe"
$testCard.middleName:="D"
$testCard.firstName:="John"
$testCard.nameSuffix:="JR"
$testCard.namePrefix:="MR"
$testCard.nickname:="Test User"
$testCard.gender:="M"
$testCard.organization:="ACME Corporation"
$testCard.photo.attachFromUrl("https://testurl"; "png")
$testCard.logo.attachFromUrl("https://testurl"; "png")
$testCard.workPhone:="312-555-1212"
$testCard.homePhone:="312-555-1313"
$testCard.cellPhone:="12345678900"
$testCard.pagerPhone:="312-555-1515"
$testCard.homeFax:="312-555-1616"
$testCard.workFax:="312-555-1717"
$testCard.birthday:=Date:C102("2018-12-01T00:00:00.0000")
$testCard.anniversary:=Date:C102("2018-12-01T00:00:00.0000")
$testCard.title:="Crash Test Dummy"
$testCard.role:="Crash Testing"
$testCard.email:="john.doe@testmail"
$testCard.workEmail:="john.doe@workmail"
$testCard.url:="http://johndoe"
$testCard.workUrl:="http://acemecompany/johndoe"
$testCard.homeAddress.label:="Home Address"
$testCard.homeAddress.street:="123 Main Street"
$testCard.homeAddress.city:="Chicago"
$testCard.homeAddress.stateProvince:="IL"
$testCard.homeAddress.postalCode:="12345"
$testCard.homeAddress.countryRegion:="United States of America"
$testCard.workAddress.label:="Work Address"
$testCard.workAddress.street:="123 Corporate Loop\nSuite 500"
$testCard.workAddress.city:="Los Angeles"
$testCard.workAddress.stateProvince:="CA"
$testCard.workAddress.postalCode:="54321"
$testCard.workAddress.countryRegion:="California Republic"
$testCard.source:="http://sourceurl"
$testCard.note:="John Doe's \nnotes;,"
$testCard.socialUrls.facebook:="https://facebook/johndoe"
$testCard.socialUrls.linkedIn:="https://linkedin/johndoe"
$testCard.socialUrls.twitter:="https://twitter/johndoe"
$testCard.socialUrls.flickr:="https://flickr/johndoe"
$testCard.socialUrls.custom:="https://custom/johndoe"
var $vCardString : Text
$vCardString:=$testCard.getText()
var $lines : Collection
$lines:=Split string:C1554($vCardString; "\r\n")
var _ : Object
_:=spec
While (_.describe(".getText"))
While (_.it("should start with BEGIN:VCARD"))
_.expect($lines.length).to(_.beGreaterThan(0))
If ($lines.length>0)
_.expect($lines[0]).to(_.beginWith("BEGIN:VCARD"))
End if
End while
While (_.it("should be well-formed"))
var $line : Text
var $segments : Collection
For each ($line; $lines)
If (Length:C16($line)>0)
$segments:=Split string:C1554($line; ":")
_.expect(($segments.length>=2) | (Position:C15(";"; $segments[0])=1)).to(_.beTrue())
End if
End for each
End while
While (_.it("should encode [\\n,',;] properly (3.0+)"))
For each ($line; $lines)
If (Position:C15("NOTE"; $line)=1)
// assert($line.indexOf('\\n') !== -1 && $line.indexOf('\\') !== -1 && $line.indexOf('\\;') !== -1);
End if
End for each
End while
While (_.it("should encode numeric input as strings"))
$testCard.workAddress.postalCode:=12345
_.expect($testCard.getText()).to(_.contain("12345")) // must not raised? // TODO better catching
End while
While (_.it("should format birthday as 20181201"))
_.expect(_getValueByFieldName("BDAY"; $lines)).to(_.beEqualTo("20181201"))
End while
While (_.it("should format anniversary as 20181201"))
_.expect(_getValueByFieldName("ANNIVERSARY"; $lines)).to(_.beEqualTo("20181201"))
End while
While (_.it("should not crash when cellPhone is a large number, using 12345678900"))
$testCard.cellPhone:=12345678900
$testCard.getText() // must not raised? // TODO better catching
End while
While (_.it("should have UID set as test value: "+$TEST_VALUE_UID))
_.expect(_getValueByFieldName("UID"; $lines)).to(_.beEqualTo($TEST_VALUE_UID))
End while
While (_.it("should end with END:VCARD"))
_.expect($lines.length).to(_.beGreaterThan(2))
If ($lines.length>2)
_.expect($lines[$lines.length-2]).to(_.beEqualTo("END:VCARD"))
End if
End while
End while
While (_.describe(".save and parse"))
var $testFile; $testFileTmp : Object
$testFile:=Folder:C1567(fk resources folder:K87:11).file("test/testCard.vcf")
$testFileTmp:=Folder:C1567(Temporary folder:C486; fk platform path:K87:2).file("testCard.vcf")
While (_.it("should save to file"))
If ($testFileTmp.exists)
$testFileTmp.delete()
End if
$testCard.saveToFile($testFileTmp)
ASSERT:C1129($testFileTmp.exists)
//ASSERT($testFileTmp.getText()=$testFile.getText()) // could not test without removing line REV:
If (Shift down:C543)
// to test
If (Windows Ctrl down:C562)
// to import it
OPEN URL:C673($testFileTmp.platformPath)
Else
// to reveal it
SHOW ON DISK:C922($testFileTmp.platformPath)
End if
Else
// clean
$testFileTmp.delete()
End if
End while
While (_.it("should parse to the file"))
$testCard:=PIM.VCard.new()
$testCard._parseFile($testFile)
End while
End while