Search in sources :

Example 1 with ObjectKey

use of com.bumptech.glide.signature.ObjectKey in project glide by bumptech.

the class EngineKeyTest method updateDiskCacheKey_throwsException.

@Test
public void updateDiskCacheKey_throwsException() throws NoSuchAlgorithmException {
    // If this test fails, update testEqualsAndHashcode to use KeyTester including regression tests.
    EngineKey key = new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options());
    expectedException.expect(UnsupportedOperationException.class);
    key.updateDiskCacheKey(MessageDigest.getInstance("SHA-1"));
}
Also used : Options(com.bumptech.glide.load.Options) ObjectKey(com.bumptech.glide.signature.ObjectKey) Test(org.junit.Test)

Example 2 with ObjectKey

use of com.bumptech.glide.signature.ObjectKey in project Camera-Roll-Android-App by kollerlukas.

the class AlbumItem method getGlideSignature.

public Key getGlideSignature() {
    File file = new File(getPath());
    String lastModified = String.valueOf(file.lastModified());
    return new ObjectKey(lastModified);
}
Also used : ObjectKey(com.bumptech.glide.signature.ObjectKey) File(java.io.File)

Example 3 with ObjectKey

use of com.bumptech.glide.signature.ObjectKey in project glide by bumptech.

the class ResourceCacheKeyTest method testEqualsAndHashCode.

@Test
public void testEqualsAndHashCode() {
    Options memoryOptions = new Options();
    memoryOptions.set(Option.memory("key", new Object()), new Object());
    Options diskOptions = new Options();
    diskOptions.set(Option.disk("key", new CacheKeyUpdater<String>() {

        @Override
        public void update(@NonNull byte[] keyBytes, @NonNull String value, @NonNull MessageDigest messageDigest) {
            messageDigest.update(keyBytes);
            messageDigest.update(value.getBytes(Key.CHARSET));
        }
    }), "value");
    for (int i = 0; i < 20; i++) {
        byte[] array = new byte[9];
        Arrays.fill(array, (byte) 2);
        arrayPool.put(array);
    }
    keyTester.addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, new Options()), new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("otherSource"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("otherSignature"), 100, 100, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 200, 100, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 200, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation2, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Integer.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, memoryOptions)).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, diskOptions)).addRegressionTest(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, new Options()), "04d632bfe8e588544909fc44edb7328fa28bea6831b96927ade22b44818654e2").addRegressionTest(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, diskOptions), "781ff8cd30aaaf248134580004ea6d63a1b87ae20ea0f769caf379d7d84986d0").test();
}
Also used : Options(com.bumptech.glide.load.Options) CacheKeyUpdater(com.bumptech.glide.load.Option.CacheKeyUpdater) NonNull(android.support.annotation.NonNull) ObjectKey(com.bumptech.glide.signature.ObjectKey) MessageDigest(java.security.MessageDigest) Test(org.junit.Test)

Example 4 with ObjectKey

use of com.bumptech.glide.signature.ObjectKey in project glide by bumptech.

the class EngineKeyTest method testEqualsAndHashCode.

@Test
public void testEqualsAndHashCode() {
    Options memoryOptions = new Options();
    memoryOptions.set(Option.memory("key", new Object()), new Object());
    Options diskOptions = new Options();
    diskOptions.set(Option.disk("key", new CacheKeyUpdater<String>() {

        @Override
        public void update(@NonNull byte[] keyBytes, @NonNull String value, @NonNull MessageDigest messageDigest) {
            messageDigest.update(keyBytes);
            messageDigest.update(value.getBytes(Key.CHARSET));
        }
    }), "value");
    new EqualsTester().addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options()), new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("otherId", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("otherSignature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 200, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 200, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>singletonMap(Object.class, transformation), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Integer.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Integer.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, memoryOptions)).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, diskOptions)).testEquals();
}
Also used : Options(com.bumptech.glide.load.Options) Transformation(com.bumptech.glide.load.Transformation) CacheKeyUpdater(com.bumptech.glide.load.Option.CacheKeyUpdater) EqualsTester(com.google.common.testing.EqualsTester) NonNull(android.support.annotation.NonNull) ObjectKey(com.bumptech.glide.signature.ObjectKey) MessageDigest(java.security.MessageDigest) Test(org.junit.Test)

Example 5 with ObjectKey

use of com.bumptech.glide.signature.ObjectKey in project glide by bumptech.

the class DiskLruCacheWrapperTest method setUp.

@Before
public void setUp() {
    dir = RuntimeEnvironment.application.getCacheDir();
    cache = DiskLruCacheWrapper.create(dir, 10 * 1024 * 1024);
    key = new ObjectKey("test" + Math.random());
    data = new byte[] { 1, 2, 3, 4, 5, 6 };
}
Also used : ObjectKey(com.bumptech.glide.signature.ObjectKey) Before(org.junit.Before)

Aggregations

ObjectKey (com.bumptech.glide.signature.ObjectKey)6 Test (org.junit.Test)4 Options (com.bumptech.glide.load.Options)3 NonNull (android.support.annotation.NonNull)2 CacheKeyUpdater (com.bumptech.glide.load.Option.CacheKeyUpdater)2 EqualsTester (com.google.common.testing.EqualsTester)2 MessageDigest (java.security.MessageDigest)2 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 Transformation (com.bumptech.glide.load.Transformation)1 File (java.io.File)1 Before (org.junit.Before)1