|
7 | 7 |
|
8 | 8 | namespace FbxExporters.UnitTests
|
9 | 9 | {
|
10 |
| - public class FbxExportSettingsTest { |
| 10 | + public class FbxExportSettingsTest : ExporterTestBase{ |
11 | 11 | ExportSettings m_originalSettings;
|
12 | 12 |
|
13 | 13 | // We read two private fields for the test.
|
@@ -213,5 +213,151 @@ public void TestFindPreferredProgram()
|
213 | 213 | Assert.AreEqual(preferred, -1);
|
214 | 214 | }
|
215 | 215 |
|
| 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 | + |
216 | 362 | }
|
217 | 363 | }
|
0 commit comments