Skip to content

Commit d202cc9

Browse files
committed
[Full API][Tests] Improve non regression test api (#64)
* [Tests] move back tests out from Editor/scripts * [Tests] Fix ScenesTEstRunner and add WriteMode and compareMode * [Tests] Add class to dump scene and mesh data in log files * [Tests] Update method to write SceneData and MeshData. Add method to load and compare data * [Tests] Update ScenesTestRunner to export all logs and load, compare them * [Tests] Add scene test references logs and captures * [Tests] Small updates * [Tests] Update all refs
1 parent 2f30fef commit d202cc9

120 files changed

Lines changed: 5042 additions & 159 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ License/SofaAPAPI-License.lic.meta
66
*.pyc
77
*.pyc.*
88
Scripts/Editor/Tests/logs/
9+
Tests/logs/

Scripts/Editor/Tests/api/ScenesTestRunner.cs

Lines changed: 0 additions & 159 deletions
This file was deleted.
File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Transform:
150150
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
151151
m_LocalPosition: {x: -0.03943566, y: -0.18681753, z: -0.058360696}
152152
m_LocalScale: {x: 1, y: 1, z: 1}
153+
m_ConstrainProportionsScale: 0
153154
m_Children: []
154155
m_Father: {fileID: 0}
155156
m_RootOrder: 0
@@ -166,3 +167,9 @@ MonoBehaviour:
166167
m_Script: {fileID: 11500000, guid: 0bbe18998f0bcc1478b6c1c056205331, type: 3}
167168
m_Name:
168169
m_EditorClassIdentifier:
170+
m_nbrTestedScenes: 0
171+
WriteRefMode: 0
172+
m_testEndoscopy: 1
173+
m_testFluoroscopy: 1
174+
m_testUltrasound: 1
175+
m_testHaptic: 0
File renamed without changes.

Tests/api/SceneTestData.cs

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using System.IO;
5+
6+
7+
public class MeshTestData
8+
{
9+
public string m_meshName = "None";
10+
public int m_nbrVertices = 0;
11+
public int m_nbrTriangles = 0;
12+
public Vector3 m_center;
13+
public Vector3 m_size;
14+
15+
16+
public bool CompareMesh(MeshTestData logMesh)
17+
{
18+
if (m_meshName != logMesh.m_meshName)
19+
{
20+
Debug.LogError("MeshName differ between ref: " + m_meshName + " and new log: " + logMesh.m_meshName);
21+
return false;
22+
}
23+
24+
if (m_nbrVertices != logMesh.m_nbrVertices)
25+
{
26+
Debug.LogError("In mesh: " + m_meshName + ". Number of vertices differ between ref: " + m_nbrVertices + " and new log: " + logMesh.m_nbrVertices);
27+
return false;
28+
}
29+
30+
if (m_nbrTriangles != logMesh.m_nbrTriangles)
31+
{
32+
Debug.LogError("In mesh: " + m_meshName + ". Number of triangles differ between ref: " + m_nbrTriangles + " and new log: " + logMesh.m_nbrTriangles);
33+
return false;
34+
}
35+
36+
if (m_center != logMesh.m_center)
37+
{
38+
Debug.LogError("In mesh: " + m_meshName + ". Mesh center differ between ref: " + m_center + " and new log: " + logMesh.m_center);
39+
return false;
40+
}
41+
42+
if (m_size != logMesh.m_size)
43+
{
44+
Debug.LogError("In mesh: " + m_meshName + ". Mesh size differ between ref: " + m_size + " and new log: " + logMesh.m_size);
45+
return false;
46+
}
47+
48+
return true;
49+
}
50+
51+
public void LogMesh()
52+
{
53+
Debug.Log("### Found Mesh: " + m_meshName + " ###");
54+
Debug.Log("nbr vertices: " + m_nbrVertices);
55+
Debug.Log("nbr triangles: " + m_nbrTriangles);
56+
Debug.Log("bounds: [" + m_center.ToString("F6") + " | " + m_size.ToString("F6") + "]");
57+
}
58+
59+
}
60+
61+
public class SceneTestData
62+
{
63+
public SceneTestData(string sceneName) { }
64+
65+
public SceneTestData(string sceneName, int nbrMeshes)
66+
{
67+
m_sceneName = sceneName;
68+
m_nbrMeshes = nbrMeshes;
69+
m_meshes = new List<MeshTestData>(nbrMeshes);
70+
}
71+
72+
73+
public void AddMeshData(MeshFilter mesh, bool log = false)
74+
{
75+
MeshTestData meshData = new MeshTestData();
76+
meshData.m_meshName = mesh.name;
77+
meshData.m_nbrVertices = mesh.mesh.vertexCount;
78+
meshData.m_nbrTriangles = mesh.mesh.triangles.Length / 3;
79+
meshData.m_center = mesh.mesh.bounds.center;
80+
meshData.m_size = mesh.mesh.bounds.size;
81+
82+
m_meshes.Add(meshData);
83+
if (log)
84+
meshData.LogMesh();
85+
}
86+
87+
88+
public void WriteData(string path)
89+
{
90+
StreamWriter writer = new StreamWriter(path, false);
91+
writer.WriteLine("NbrMeshes: " + m_nbrMeshes);
92+
93+
foreach (MeshTestData mesh in m_meshes)
94+
{
95+
writer.WriteLine("Mesh: " + mesh.m_meshName);
96+
writer.WriteLine("NbrVertices: " + mesh.m_nbrVertices);
97+
writer.WriteLine("NbrTriangles: " + mesh.m_nbrTriangles);
98+
writer.WriteLine("Center: " + mesh.m_center.x + ";" + mesh.m_center.y + ";" + mesh.m_center.z);
99+
writer.WriteLine("Min: " + mesh.m_size.x + ";" + mesh.m_size.y + ";" + mesh.m_size.z);
100+
}
101+
102+
writer.Close();
103+
}
104+
105+
106+
public void ReadData(string path, bool log = false)
107+
{
108+
StreamReader reader = new StreamReader(path);
109+
110+
// get number of meshes
111+
string meshLine = reader.ReadLine();
112+
int nbrMesh = int.Parse(meshLine.Split(" ")[1]);
113+
114+
for (int cptMesh = 0; cptMesh< nbrMesh; cptMesh++)
115+
{
116+
MeshTestData meshData = new MeshTestData();
117+
118+
string nameLine = reader.ReadLine();
119+
meshData.m_meshName = nameLine.Split(" ")[1];
120+
121+
string verticesLine = reader.ReadLine();
122+
meshData.m_nbrVertices = int.Parse(verticesLine.Split(" ")[1]);
123+
124+
string trianglesLine = reader.ReadLine();
125+
meshData.m_nbrTriangles = int.Parse(trianglesLine.Split(" ")[1]);
126+
127+
string centerLine = reader.ReadLine();
128+
centerLine = centerLine.Split(" ")[1];
129+
string[] centerString = centerLine.Split(";");
130+
meshData.m_center = new Vector3(float.Parse(centerString[0]), float.Parse(centerString[1]), float.Parse(centerString[2]));
131+
132+
string sizeLine = reader.ReadLine();
133+
sizeLine = sizeLine.Split(" ")[1];
134+
string[] sizeString = sizeLine.Split(";");
135+
meshData.m_size = new Vector3(float.Parse(sizeString[0]), float.Parse(sizeString[1]), float.Parse(sizeString[2]));
136+
137+
if (log)
138+
meshData.LogMesh();
139+
}
140+
141+
reader.Close();
142+
}
143+
144+
public bool CompareScene(SceneTestData otherScene)
145+
{
146+
if (otherScene.m_nbrMeshes != m_nbrMeshes)
147+
{
148+
Debug.LogError("In scene: " + m_sceneName + ". Number of mesh differ between ref: " + m_nbrMeshes + " and new log: " + otherScene.m_nbrMeshes);
149+
return false;
150+
}
151+
152+
for (int i=0; i<m_nbrMeshes; ++i)
153+
{
154+
bool res = m_meshes[i].CompareMesh(otherScene.m_meshes[i]);
155+
if (!res)
156+
return false;
157+
}
158+
159+
return true;
160+
}
161+
162+
163+
private readonly string m_sceneName;
164+
private readonly int m_nbrMeshes;
165+
private List<MeshTestData> m_meshes = null;
166+
167+
}
168+

Tests/api/SceneTestData.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)