Skip to content

Commit d598678

Browse files
committed
Fix Tests for Linux/OS X
1 parent eb80232 commit d598678

File tree

102 files changed

+75
-9987
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+75
-9987
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,6 @@ $RECYCLE.BIN/
6666
.idea/*
6767
example_output/*
6868

69-
Assets/MyAWSCredentials.asset*
69+
Assets/MyAWSCredentials.asset*
70+
71+
UserSettings/
Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
11
using UnityEngine;
2-
using UnityEditor;
3-
using UnityEngine.Events;
4-
using UnityEngine.TestTools;
52
using System.Collections.Generic;
63
using NUnit.Framework;
7-
using System.Collections;
84
using System.IO;
95

106
namespace UXF.Tests
117
{
12-
138
public class TestFileSaver
149
{
15-
1610
string experiment = "fileSaver_test";
1711
string ppid = "test_ppid";
1812
int sessionNum = 1;
19-
FileSaver fileSaver;
13+
FileSaver fileSaver;
2014

2115
[SetUp]
2216
public void SetUp()
2317
{
24-
var gameObject = new GameObject();
25-
fileSaver = gameObject.AddComponent<FileSaver>();
26-
fileSaver.verboseDebug = true;
18+
var gameObject = new GameObject();
19+
fileSaver = gameObject.AddComponent<FileSaver>();
20+
fileSaver.verboseDebug = true;
2721
}
2822

2923

30-
[TearDown]
31-
public void TearDown()
32-
{
33-
GameObject.DestroyImmediate(fileSaver.gameObject);
34-
}
24+
[TearDown]
25+
public void TearDown()
26+
{
27+
GameObject.DestroyImmediate(fileSaver.gameObject);
28+
}
3529

3630

3731
[Test]
@@ -41,32 +35,34 @@ public void WriteManyFiles()
4135
fileSaver.SetUp();
4236

4337
// generate a large dictionary
44-
var dict = new Dictionary<string, object>();
38+
var dict = new Dictionary<string, object>();
4539

4640
var largeArray = new string[100];
4741
string largeString = new string('*', 50000);
4842

49-
// write lots and lots of JSON files
50-
int n = 100;
43+
// write lots and lots of JSON files
44+
int n = 100;
5145
string[] fpaths = new string[n];
52-
for (int i = 0; i < n; i++)
53-
{
54-
string fileName = string.Format("{0}", i);
55-
Debug.LogFormat("Queueing {0}", fileName);
56-
string fpath = fileSaver.HandleText(largeString, experiment, ppid, sessionNum, fileName, UXFDataType.OtherSessionData);
46+
for (int i = 0; i < n; i++)
47+
{
48+
string fileName = string.Format("{0}", i);
49+
Debug.LogFormat("Queueing {0}", fileName);
50+
string fpath = fileSaver.HandleText(largeString, experiment, ppid, sessionNum, fileName,
51+
UXFDataType.OtherSessionData);
5752
fpaths[i] = fpath;
58-
}
53+
}
5954

6055
Debug.Log("###########################################");
6156
Debug.Log("############## CLEANING UP ################");
6257
Debug.Log("###########################################");
6358
fileSaver.CleanUp();
6459

65-
Assert.Throws<System.InvalidOperationException>(() => {
60+
Assert.Throws<System.InvalidOperationException>(() =>
61+
{
6662
fileSaver.HandleText(largeString, experiment, ppid, sessionNum, "0", UXFDataType.OtherSessionData);
6763
});
6864

69-
// cleanup files
65+
// cleanup files
7066
foreach (var fpath in fpaths)
7167
{
7268
System.IO.File.Delete(Path.Combine(fileSaver.StoragePath, fpath));
@@ -80,12 +76,10 @@ public void EarlyExit()
8076
fileSaver.StoragePath = "example_output";
8177
fileSaver.SetUp();
8278
fileSaver.CleanUp();
83-
84-
Assert.Throws<System.InvalidOperationException>(
85-
() => {
86-
fileSaver.ManageInWorker(() => Debug.Log("Code enqueued after FileSaver ended"));
87-
}
88-
);
79+
80+
Assert.Throws<System.InvalidOperationException>(
81+
() => { fileSaver.ManageInWorker(() => Debug.Log("Code enqueued after FileSaver ended")); }
82+
);
8983

9084
fileSaver.SetUp();
9185
fileSaver.ManageInWorker(() => Debug.Log("Code enqueued after FileSaver re-opened"));
@@ -95,10 +89,18 @@ public void EarlyExit()
9589
[Test]
9690
public void AbsolutePath()
9791
{
98-
fileSaver.StoragePath = "C:/example_output";
92+
if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows)
93+
{
94+
fileSaver.StoragePath = "C:/example_output";
95+
}
96+
else
97+
{
98+
fileSaver.StoragePath = "/tmp/example_output";
99+
}
99100
fileSaver.SetUp();
100-
101-
string outString = fileSaver.HandleText("abc", experiment, ppid, sessionNum, "test", UXFDataType.OtherSessionData);
101+
102+
string outString =
103+
fileSaver.HandleText("abc", experiment, ppid, sessionNum, "test", UXFDataType.OtherSessionData);
102104

103105
Assert.AreEqual(outString, @"fileSaver_test/test_ppid/S001/other/test.txt");
104106

@@ -115,18 +117,18 @@ public void PersistentDataPath()
115117
string dataOutput = "abc";
116118
fileSaver.HandleText(dataOutput, experiment, ppid, sessionNum, "test", UXFDataType.OtherSessionData);
117119
fileSaver.CleanUp();
118-
string outFile = Path.Combine(Application.persistentDataPath, @"fileSaver_test/test_ppid/S001/other/test.txt");
120+
string outFile = Path.Combine(Application.persistentDataPath,
121+
@"fileSaver_test/test_ppid/S001/other/test.txt");
119122

120123
string readData = File.ReadAllText(outFile);
121124
Assert.AreEqual(dataOutput, readData);
122-
125+
123126
if (File.Exists(outFile)) File.Delete(outFile);
124127
}
125128

126129
[Test]
127130
public void FileSaverRelPath()
128131
{
129-
130132
Assert.AreEqual(
131133
FileSaver.GetRelativePath("C:\\base", "C:\\base\\123"),
132134
"123"
@@ -139,15 +141,13 @@ public void FileSaverRelPath()
139141

140142
Assert.AreEqual(
141143
FileSaver.GetRelativePath("base/", "base\\123"),
142-
"123"
144+
SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows ? "123" : "../123"
143145
);
144146

145147
Assert.AreEqual(
146148
FileSaver.GetRelativePath("C:/base/", "C:/base\\123"),
147-
"123"
149+
SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows ? "123" : "../123"
148150
);
149151
}
150-
151152
}
152-
153-
}
153+
}

Assets/UXF/Tests/Editor/TestJSON.cs

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
using UnityEngine;
2-
using UnityEditor;
3-
using UnityEngine.TestTools;
42
using NUnit.Framework;
5-
using System.Collections;
63
using System.Collections.Generic;
7-
using System.IO;
84

95
namespace UXF.Tests
106
{
11-
public class TestJSON
12-
{
7+
public class TestJSON
8+
{
9+
Dictionary<string, object> dict = new Dictionary<string, object>()
10+
{
11+
{"string", "aaa"},
12+
{"bool", true},
13+
{"int", 3},
14+
{"float", 3.14f},
15+
{"list", new List<object>() {1, 2, 3, 4}},
16+
{"array", new object[] {1, 2, 3, 4}},
17+
{"object", new Dictionary<string, object>() {{"a", 1}, {"b", "abc"}}}
18+
};
1319

14-
Dictionary<string, object> dict = new Dictionary<string, object>()
15-
{
16-
{"string", "aaa"},
17-
{"bool", true},
18-
{"int", 3},
19-
{"float", 3.14f},
20-
{"list", new List<object>(){1, 2, 3, 4}},
21-
{"array", new object[]{1, 2, 3, 4}},
22-
{"object", new Dictionary<string, object>(){{"a", 1}, {"b", "abc"}}}
23-
};
24-
25-
const string jsonString = @"{
20+
const string jsonString = @"{
2621
""string"": ""aaa"",
2722
""bool"": true,
2823
""int"": 3,
@@ -46,22 +41,22 @@ public class TestJSON
4641
}";
4742

4843

49-
[Test]
50-
public void JSONIndentation()
51-
{
52-
string outString = MiniJSON.Json.Serialize(dict);
53-
Assert.AreEqual(jsonString, outString);
54-
}
44+
[Test]
45+
public void JSONIndentation()
46+
{
47+
string outString = MiniJSON.Json.Serialize(dict);
48+
Assert.AreEqual(jsonString, outString.Replace("\r", ""));
49+
}
5550

56-
[Test]
57-
public void VectorSerialize()
58-
{
51+
[Test]
52+
public void VectorSerialize()
53+
{
5954
var vectorDict = new Dictionary<string, object>
6055
{
61-
{ "vector3", new Vector3(1, 2, 3) },
62-
{ "vector2", new Vector2(1, 2) }
56+
{"vector3", new Vector3(1, 2, 3)},
57+
{"vector2", new Vector2(1, 2)}
6358
};
64-
59+
6560
string vectorString = @"{
6661
""vector3"": {
6762
""x"": 1,
@@ -73,11 +68,9 @@ public void VectorSerialize()
7368
""y"": 2
7469
}
7570
}";
76-
77-
string outString = MiniJSON.Json.Serialize(vectorDict);
78-
Assert.AreEqual(vectorString, outString);
79-
}
80-
81-
}
8271

72+
string outString = MiniJSON.Json.Serialize(vectorDict);
73+
Assert.AreEqual(vectorString, outString.Replace("\r", ""));
74+
}
75+
}
8376
}

example_output/basic_example_1/arson-118b23f9-c877-4cb7-9053-a47e1318b95b/S001/sessioninfo/log.csv

Lines changed: 0 additions & 41 deletions
This file was deleted.

example_output/basic_example_1/arson-118b23f9-c877-4cb7-9053-a47e1318b95b/S001/sessioninfo/participant_details.csv

Lines changed: 0 additions & 2 deletions
This file was deleted.

example_output/basic_example_1/arson-118b23f9-c877-4cb7-9053-a47e1318b95b/S001/sessioninfo/settings.csv

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)