TestUtil.cs 990 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO;
  5. namespace Google.ProtocolBuffers {
  6. internal static class TestUtil {
  7. private static DirectoryInfo testDataDirectory;
  8. internal static DirectoryInfo TestDataDirectory {
  9. get {
  10. if (testDataDirectory != null) {
  11. return testDataDirectory;
  12. }
  13. DirectoryInfo ancestor = new DirectoryInfo(".");
  14. // Search each parent directory looking for "src/google/protobuf".
  15. while (ancestor != null) {
  16. string candidate = Path.Combine(ancestor.FullName, "src/google/protobuf");
  17. if (Directory.Exists(candidate)) {
  18. testDataDirectory = new DirectoryInfo(candidate);
  19. return testDataDirectory;
  20. }
  21. ancestor = ancestor.Parent;
  22. }
  23. // TODO(jonskeet): Come up with a better exception to throw
  24. throw new Exception("Unable to find directory containing test files");
  25. }
  26. }
  27. }
  28. }