You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestUtilTest.java 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  3. * This file is part of the compiler and core tools for the AspectJ(tm)
  4. * programming language; see http://aspectj.org
  5. *
  6. * The contents of this file are subject to the Mozilla Public License
  7. * Version 1.1 (the "License"); you may not use this file except in
  8. * compliance with the License. You may obtain a copy of the License at
  9. * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. *
  16. * The Original Code is AspectJ.
  17. *
  18. * The Initial Developer of the Original Code is Xerox Corporation. Portions
  19. * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
  20. * All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. */
  24. package org.aspectj.testing.util;
  25. import org.aspectj.bridge.IMessageHolder;
  26. import org.aspectj.bridge.MessageHandler;
  27. import org.aspectj.bridge.MessageUtil;
  28. import org.aspectj.util.FileUtil;
  29. import java.io.File;
  30. import java.io.IOException;
  31. import junit.framework.TestCase;
  32. /**
  33. *
  34. */
  35. public class TestUtilTest extends TestCase {
  36. public TestUtilTest(String name) {
  37. super(name);
  38. }
  39. public void testFileCompareNonClass() throws IOException {
  40. MessageHandler holder = new MessageHandler();
  41. File thisFile = new File("testsrc/org/aspectj/testing/util/TestUtilTest.java");
  42. //File thisFile = new File("src/testing-util.lst");
  43. assertTrue(TestUtil.sameFiles(holder, thisFile, thisFile));
  44. File tempFile = File.createTempFile("TestUtilTest", ".tmp");
  45. FileUtil.copyFile(thisFile, tempFile);
  46. long len = tempFile.length();
  47. assertTrue(0 != len);
  48. long tlen = thisFile.length();
  49. assertEquals(tlen, len);
  50. assertTrue(TestUtil.sameFiles(holder, tempFile, thisFile));
  51. try {
  52. String path = thisFile.getName();
  53. File basedir = tempFile.getParentFile();
  54. File renamed = new File(basedir, path);
  55. if (!tempFile.renameTo(renamed)) {
  56. MessageUtil.warn(holder, "unable to rename " + tempFile + " to " + renamed);
  57. } else {
  58. len = renamed.length();
  59. assertEquals(tlen, len);
  60. assertTrue(TestUtil.sameFiles(holder, basedir, thisFile.getParentFile(), path));
  61. }
  62. } finally {
  63. if (0 < holder.numMessages(null, true)) {
  64. MessageUtil.print(System.out, holder);
  65. holder.clear();
  66. }
  67. tempFile.delete();
  68. }
  69. }
  70. public void testFileCompareClass() throws IOException {
  71. MessageHandler holder = new MessageHandler();
  72. File classBase = new File("testdata/testCompareClassFiles");
  73. String path = "org/aspectj/testing/util/TestCompareClassFile.class";
  74. File classFile = new File(classBase, path);
  75. try {
  76. assertTrue(TestUtil.sameFiles(holder, classFile, classFile));
  77. assertTrue(TestUtil.sameFiles(holder, classBase, classBase, path));
  78. } finally {
  79. if (0 < holder.numMessages(null, true)) {
  80. MessageUtil.print(System.out, holder);
  81. }
  82. }
  83. }
  84. }