aboutsummaryrefslogtreecommitdiffstats
path: root/weaver/testsrc
diff options
context:
space:
mode:
authorAndy Clement <andrew.clement@gmail.com>2012-10-01 15:09:15 -0700
committerAndy Clement <andrew.clement@gmail.com>2012-10-01 15:09:15 -0700
commit8a6608f4d5d1a2aa8aa49a0a38da66a54d53c917 (patch)
treeeb9e96e988a63e1aa48896b279adae9bc41f9084 /weaver/testsrc
parent9a3cc2bc5c824d252140fb3d1e2e27f2163e6d53 (diff)
downloadaspectj-8a6608f4d5d1a2aa8aa49a0a38da66a54d53c917.tar.gz
aspectj-8a6608f4d5d1a2aa8aa49a0a38da66a54d53c917.zip
386341
Diffstat (limited to 'weaver/testsrc')
-rw-r--r--weaver/testsrc/org/aspectj/weaver/tools/cache/CacheTests.java1
-rw-r--r--weaver/testsrc/org/aspectj/weaver/tools/cache/SimpleClassCacheTest.java79
2 files changed, 80 insertions, 0 deletions
diff --git a/weaver/testsrc/org/aspectj/weaver/tools/cache/CacheTests.java b/weaver/testsrc/org/aspectj/weaver/tools/cache/CacheTests.java
index a87b1eba3..861f637fc 100644
--- a/weaver/testsrc/org/aspectj/weaver/tools/cache/CacheTests.java
+++ b/weaver/testsrc/org/aspectj/weaver/tools/cache/CacheTests.java
@@ -20,6 +20,7 @@ import junit.framework.TestSuite;
public class CacheTests {
public static Test suite() {
TestSuite suite = new TestSuite(CacheTests.class.getName());
+ suite.addTestSuite(SimpleClassCacheTest.class);
suite.addTestSuite(WeavedClassCacheTest.class);
suite.addTestSuite(DefaultCacheKeyResolverTest.class);
suite.addTestSuite(DefaultFileCacheBackingTest.class);
diff --git a/weaver/testsrc/org/aspectj/weaver/tools/cache/SimpleClassCacheTest.java b/weaver/testsrc/org/aspectj/weaver/tools/cache/SimpleClassCacheTest.java
new file mode 100644
index 000000000..0624d0ff0
--- /dev/null
+++ b/weaver/testsrc/org/aspectj/weaver/tools/cache/SimpleClassCacheTest.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Abraham Nevado (lucierna) initial implementation
+ ********************************************************************************/
+
+package org.aspectj.weaver.tools.cache;
+
+import junit.framework.TestCase;
+import org.aspectj.bridge.AbortException;
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.IMessageHandler;
+import org.aspectj.weaver.tools.GeneratedClassHandler;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ */
+public class SimpleClassCacheTest extends TestCase {
+ byte[] FAKE_BYTES_V1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+ byte[] FAKE_BYTES_V2 = {1, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+
+ byte[] FAKE_WOVEN_BYTES_V1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10};
+ byte[] FAKE_WOVEN_BYTES_V2 = {1, 1, 2, 3, 4, 5, 6, 7, 8, 9,10};
+
+
+ private SimpleCache createCache() throws Exception {
+ return new SimpleCache(System.getProperty("java.io.tmpdir"),true);
+ }
+
+
+ public void testCache() throws Exception {
+ String classA = "com.generated.A";
+ SimpleCache cache = createCache();
+
+ cache.put(classA, FAKE_BYTES_V1, FAKE_WOVEN_BYTES_V1);
+
+
+ // Test the returned woven bytes are the original one
+ byte result[] = cache.getAndInitialize(classA, FAKE_BYTES_V1, null, null);
+ for(int i = 0; i < result.length; i ++){
+ assertEquals("Cached version byte[" +i+"] should be equal to the original woven classe",result[i],FAKE_WOVEN_BYTES_V1[i]);
+ }
+
+ // Assure the class is properly backed up in the backing folder
+ File f = new File (System.getProperty("java.io.tmpdir") + File.separator + "com.generated.A-1164760902");
+ assertTrue("Class should be backed up to backing folder, with te CRC:1164760902 ",f.exists());
+
+ }
+
+ public void testDifferentVersionCache() throws Exception {
+ String classA = "com.generated.A";
+ SimpleCache cache = createCache();
+ cache.put(classA, FAKE_BYTES_V1, FAKE_WOVEN_BYTES_V1);
+ cache.put(classA, FAKE_BYTES_V2, FAKE_WOVEN_BYTES_V2);
+
+ // Test the returned woven bytes are the original one for v1
+ byte result[] = cache.getAndInitialize(classA, FAKE_BYTES_V1, null, null);
+ for(int i = 0; i < result.length; i ++){
+ assertEquals("Cached version v1 byte[" +i+"] should be equal to the original woven classe",result[i],FAKE_WOVEN_BYTES_V1[i]);
+ }
+
+ // Test the returned woven bytes are the original one for v2
+ result = cache.getAndInitialize(classA, FAKE_BYTES_V2, null, null);
+ for(int i = 0; i < result.length; i ++){
+ assertEquals("Cached version v2 byte[" +i+"] should be equal to the original woven classe",result[i],FAKE_WOVEN_BYTES_V2[i]);
+ }
+ }
+} \ No newline at end of file