Skip to content

Commit 64f9648

Browse files
author
AJubrey
committed
[ADDED] tests for the building and acquisition of Dccs using the environment variables
[CHANGED] made the fbxsettings test class a child of the exportertestbase so we'd have access to the test functions, not sure why it wasn't already?
1 parent c4340e7 commit 64f9648

File tree

2 files changed

+152
-3
lines changed

2 files changed

+152
-3
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,6 @@ private static string GetMayaLocationFromEnvironmentVariable(string env)
300300
}
301301
}
302302
}
303-
304-
Debug.Log(string.Format("found location {0}",result));
305303
return result;
306304
}
307305

@@ -683,6 +681,11 @@ private static string GetMayaExePathFromLocation(string location)
683681
}
684682
}
685683

684+
public void SetDCCOptionPaths(List<string> newList)
685+
{
686+
dccOptionPaths = newList;
687+
}
688+
686689
public static GUIContent[] GetDCCOptions(){
687690
if (instance.dccOptionNames == null ||
688691
instance.dccOptionNames.Count != instance.dccOptionPaths.Count ||

Assets/FbxExporters/Editor/UnitTests/FbxExportSettingsTest.cs

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace FbxExporters.UnitTests
99
{
10-
public class FbxExportSettingsTest {
10+
public class FbxExportSettingsTest : ExporterTestBase{
1111
ExportSettings m_originalSettings;
1212

1313
// We read two private fields for the test.
@@ -213,5 +213,151 @@ public void TestFindPreferredProgram()
213213
Assert.AreEqual(preferred, -1);
214214
}
215215

216+
[Test]
217+
public void FindDCCInstallsTest1()
218+
{
219+
string rootDir1 = GetRandomFileNamePath(extName: "");
220+
string rootDir2 = GetRandomFileNamePath(extName: "");
221+
222+
var data = new List<Dictionary<string, List<string>>>()
223+
{
224+
#region valid test case 1 data (unique locations, one in vendor, one for maya_loc)
225+
new Dictionary<string,List<string>>()
226+
{
227+
{"VENDOR_INSTALLS", new List<string>(){ rootDir1 + "/Maya2017/bin/maya.exe", rootDir2 + "/Maya2018/bin/maya.exe"} },
228+
{"VENDOR_LOCATIONS", new List<string>(){ rootDir1 } },
229+
{"MAYA_LOCATION", new List<string>(){ rootDir2 + "/Maya2018" } },
230+
{"expectedResult", new List<string>(){ 2.ToString() }}
231+
},
232+
new Dictionary<string,List<string>>()
233+
{
234+
{"VENDOR_INSTALLS", new List<string>(){ rootDir1 + "/Maya2017/bin/maya.exe", rootDir2 + "/MayaLT2018/bin/maya.exe" } },
235+
{"VENDOR_LOCATIONS", new List<string>(){ rootDir1 } },
236+
{"MAYA_LOCATION", new List<string>(){ rootDir2 + "/MayaLT2018" } },
237+
{"expectedResult", new List<string>(){ 2.ToString() }}
238+
},
239+
new Dictionary<string,List<string>>()
240+
{
241+
{"VENDOR_INSTALLS", new List<string>(){ rootDir1 + "/MayaLT2017/bin/maya.exe", rootDir2 + "/Maya2018/bin/maya.exe" } },
242+
{"VENDOR_LOCATIONS", new List<string>(){ rootDir1 } },
243+
{"MAYA_LOCATION", new List<string>(){ rootDir2 + "/Maya2018" } },
244+
{"expectedResult", new List<string>(){ 2.ToString() }}
245+
},
246+
new Dictionary<string,List<string>>()
247+
{
248+
{"VENDOR_INSTALLS", new List<string>(){ rootDir1 + "/MayaLT2017/bin/maya.exe", rootDir2 + "/MayaLT2018/bin/maya.exe" } },
249+
{"VENDOR_LOCATIONS", new List<string>(){ rootDir1 } },
250+
{"MAYA_LOCATION", new List<string>(){ rootDir2 + "/MayaLT2018" } },
251+
{"expectedResult", new List<string>(){ 2.ToString() }}
252+
},
253+
new Dictionary<string,List<string>>()
254+
{
255+
{"VENDOR_INSTALLS", new List<string>(){ rootDir1 + "/3ds Max 2017/3dsmax.exe", rootDir2 + "/Maya2018/bin/maya.exe" } },
256+
{"VENDOR_LOCATIONS", new List<string>(){ rootDir1 } },
257+
{"MAYA_LOCATION", new List<string>(){ rootDir2 + "/Maya2018" } },
258+
{"expectedResult", new List<string>(){ 2.ToString() }}
259+
},
260+
new Dictionary<string,List<string>>()
261+
{
262+
{"VENDOR_INSTALLS", new List<string>(){ rootDir1 + "/3ds Max 2017/3dsmax.exe", rootDir2 + "/MayaLT2018/bin/maya.exe" } },
263+
{"VENDOR_LOCATIONS", new List<string>(){ rootDir1 } },
264+
{"MAYA_LOCATION", new List<string>(){ rootDir2 + "/MayaLT2018" } },
265+
{"expectedResult", new List<string>(){ 2.ToString() }}
266+
},
267+
#endregion
268+
};
269+
270+
for (int idx = 0; idx < data.Count; idx++)
271+
{
272+
List<string> vendorInstallFolders = data[idx]["VENDOR_INSTALLS"];
273+
string envVendorLocations = string.Join(";", data[idx]["VENDOR_LOCATIONS"].ToArray());
274+
string envMayaLocation = data[idx]["MAYA_LOCATION"][0];
275+
int expectedResult = int.Parse(data[idx]["expectedResult"][0]);
276+
277+
//SetUp
278+
//make the hierarchy for the single app path we need
279+
CreateDummyInstalls(vendorInstallFolders);
280+
281+
TestLocations(envVendorLocations, envMayaLocation, expectedResult);
282+
283+
//TearDown
284+
VendorLocations_TearDown(vendorInstallFolders);
285+
}
286+
}
287+
288+
//TearDown
289+
public void VendorLocations_TearDown(List<string> vendorInstallFolders)
290+
{
291+
//Clean up vendor location(s)
292+
foreach (var vendorLocation in vendorInstallFolders)
293+
{
294+
Directory.Delete(Directory.GetParent(Path.GetDirectoryName(vendorLocation)).FullName, true);
295+
}
296+
}
297+
298+
public void TestLocations(string vendorLocation, string mayaLocation, int expectedResult)
299+
{
300+
//Mayalocation should remain a List because we want to keep using the dictionary which must be of lists (maybe should make an overload)
301+
302+
//Set Environment Variables
303+
SetEnvironmentVariables(vendorLocation, mayaLocation);
304+
305+
//Nullify these lists so that we guarantee that FindDccInstalls will be called.
306+
ExportSettings.instance.SetDCCOptionNames(null);
307+
ExportSettings.instance.SetDCCOptionPaths(null);
308+
309+
GUIContent[] options = ExportSettings.GetDCCOptions();
310+
311+
#region //LOGS TO DISPLAY WHAT WE'RE TESTING
312+
Debug.Log("Directories in VendorLocation:");
313+
foreach (var directory in Directory.GetDirectories(vendorLocation))
314+
{
315+
Debug.Log(directory);
316+
}
317+
318+
Debug.Log("MAYA_LOCATION: \n" + mayaLocation);
319+
320+
Debug.Log("END OF TEST \n \n");
321+
#endregion
322+
323+
Assert.AreEqual(options.Length, expectedResult);
324+
325+
}
326+
327+
/// <summary>
328+
/// Sets environment variables to what is passed in, resets the dccOptionNames & dccOptionPaths, and calls FindDCCInstalls()
329+
/// </summary>
330+
/// <param name="vendorLocations"></param>
331+
/// <param name="mayaLocationPath"></param>
332+
public void SetEnvironmentVariables(string vendorLocation, string mayaLocationPath)
333+
{
334+
if (vendorLocation != null)
335+
{
336+
//if the given vendor location isn't null, set the environment variable to it.
337+
System.Environment.SetEnvironmentVariable("UNITY_FBX_3DAPP_VENDOR_LOCATIONS", vendorLocation);
338+
}
339+
if (mayaLocationPath != null)
340+
{
341+
//if the given MAYA_LOCATION isn't null, set the environment variable to it
342+
System.Environment.SetEnvironmentVariable("MAYA_LOCATION", mayaLocationPath);
343+
}
344+
}
345+
346+
public void CreateDummyInstalls(List<string> paths)
347+
{
348+
foreach (var pathToExe in paths)
349+
{
350+
//make the directory
351+
Directory.CreateDirectory(Path.GetDirectoryName(pathToExe));
352+
if (Path.GetFileName(pathToExe) != null)
353+
{
354+
355+
//make the file (if we can)
356+
FileInfo newExe = new FileInfo(pathToExe);
357+
using (FileStream s = newExe.Create()) { }
358+
}
359+
}
360+
}
361+
216362
}
217363
}

0 commit comments

Comments
 (0)