2012-02-17 09:34:10 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The K-9 Dog Walkers
|
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-12-18 03:33:09 -05:00
|
|
|
package com.fsck.k9.mail.store.imap;
|
2012-02-17 09:34:10 -05:00
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
import org.junit.Test;
|
2015-05-20 13:21:33 -04:00
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
import org.robolectric.RobolectricTestRunner;
|
|
|
|
import org.robolectric.annotation.Config;
|
2014-12-18 05:56:02 -05:00
|
|
|
|
2012-02-17 09:34:10 -05:00
|
|
|
import java.util.List;
|
2014-12-12 10:02:59 -05:00
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
import static org.junit.Assert.assertArrayEquals;
|
|
|
|
|
2012-02-17 09:34:10 -05:00
|
|
|
|
2015-05-20 13:21:33 -04:00
|
|
|
@RunWith(RobolectricTestRunner.class)
|
|
|
|
@Config(manifest = Config.NONE)
|
2014-12-18 05:56:02 -05:00
|
|
|
public class ImapUtilityTest {
|
|
|
|
@Test
|
2012-02-17 09:34:10 -05:00
|
|
|
public void testGetImapSequenceValues() {
|
|
|
|
String[] expected;
|
|
|
|
List<String> actual;
|
|
|
|
|
|
|
|
// Test valid sets
|
|
|
|
expected = new String[] {"1"};
|
|
|
|
actual = ImapUtility.getImapSequenceValues("1");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
2012-07-07 10:21:07 -04:00
|
|
|
expected = new String[] {"2147483648"}; // Integer.MAX_VALUE + 1
|
|
|
|
actual = ImapUtility.getImapSequenceValues("2147483648");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-07-07 10:21:07 -04:00
|
|
|
|
|
|
|
expected = new String[] {"4294967295"}; // 2^32 - 1
|
|
|
|
actual = ImapUtility.getImapSequenceValues("4294967295");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-07-07 10:21:07 -04:00
|
|
|
|
2012-02-17 09:34:10 -05:00
|
|
|
expected = new String[] {"1", "3", "2"};
|
|
|
|
actual = ImapUtility.getImapSequenceValues("1,3,2");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
expected = new String[] {"4", "5", "6"};
|
|
|
|
actual = ImapUtility.getImapSequenceValues("4:6");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
expected = new String[] {"9", "8", "7"};
|
|
|
|
actual = ImapUtility.getImapSequenceValues("9:7");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
expected = new String[] {"1", "2", "3", "4", "9", "8", "7"};
|
|
|
|
actual = ImapUtility.getImapSequenceValues("1,2:4,9:7");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
2012-07-07 10:21:07 -04:00
|
|
|
// Test numbers larger than Integer.MAX_VALUE (2147483647)
|
|
|
|
expected = new String[] {"2147483646", "2147483647", "2147483648"};
|
|
|
|
actual = ImapUtility.getImapSequenceValues("2147483646:2147483648");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-07-07 10:21:07 -04:00
|
|
|
|
2012-02-17 09:34:10 -05:00
|
|
|
// Test partially invalid sets
|
|
|
|
expected = new String[] { "1", "5" };
|
|
|
|
actual = ImapUtility.getImapSequenceValues("1,x,5");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
expected = new String[] { "1", "2", "3" };
|
|
|
|
actual = ImapUtility.getImapSequenceValues("a:d,1:3");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
// Test invalid sets
|
|
|
|
expected = new String[0];
|
|
|
|
actual = ImapUtility.getImapSequenceValues("");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
expected = new String[0];
|
|
|
|
actual = ImapUtility.getImapSequenceValues(null);
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
expected = new String[0];
|
|
|
|
actual = ImapUtility.getImapSequenceValues("a");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
expected = new String[0];
|
|
|
|
actual = ImapUtility.getImapSequenceValues("1:x");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-07-07 10:21:07 -04:00
|
|
|
|
|
|
|
// Test values larger than 2^32 - 1
|
|
|
|
expected = new String[0];
|
|
|
|
actual = ImapUtility.getImapSequenceValues("4294967296:4294967297");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-07-07 10:21:07 -04:00
|
|
|
|
|
|
|
expected = new String[0];
|
|
|
|
actual = ImapUtility.getImapSequenceValues("4294967296"); // 2^32
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testGetImapRangeValues() {
|
2012-02-17 09:34:10 -05:00
|
|
|
String[] expected;
|
|
|
|
List<String> actual;
|
|
|
|
|
|
|
|
// Test valid ranges
|
|
|
|
expected = new String[] {"1", "2", "3"};
|
|
|
|
actual = ImapUtility.getImapRangeValues("1:3");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
expected = new String[] {"16", "15", "14"};
|
|
|
|
actual = ImapUtility.getImapRangeValues("16:14");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
// Test in-valid ranges
|
|
|
|
expected = new String[0];
|
|
|
|
actual = ImapUtility.getImapRangeValues("");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
expected = new String[0];
|
|
|
|
actual = ImapUtility.getImapRangeValues(null);
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
expected = new String[0];
|
|
|
|
actual = ImapUtility.getImapRangeValues("a");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
expected = new String[0];
|
|
|
|
actual = ImapUtility.getImapRangeValues("6");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
expected = new String[0];
|
|
|
|
actual = ImapUtility.getImapRangeValues("1:3,6");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
expected = new String[0];
|
|
|
|
actual = ImapUtility.getImapRangeValues("1:x");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
|
|
|
|
expected = new String[0];
|
|
|
|
actual = ImapUtility.getImapRangeValues("1:*");
|
2014-12-18 05:56:02 -05:00
|
|
|
assertArrayEquals(expected, actual.toArray());
|
2012-02-17 09:34:10 -05:00
|
|
|
}
|
|
|
|
}
|