aboutsummaryrefslogtreecommitdiff
path: root/WordPress/src/androidTest/java/org/wordpress/android/database/CommentTableTest.java
blob: 1f3aaee866b5889bdb22256466d76f262a7bf828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package org.wordpress.android.database;

import android.content.Context;
import android.test.InstrumentationTestCase;
import android.test.RenamingDelegatingContext;

import org.wordpress.android.TestUtils;
import org.wordpress.android.datasets.CommentTable;
import org.wordpress.android.models.Comment;

public class CommentTableTest extends InstrumentationTestCase {
    protected Context mTargetContext;
    protected Context mTestContext;

    @Override
    protected void setUp() throws Exception {
        // Clean application state
        mTargetContext = new RenamingDelegatingContext(getInstrumentation().getTargetContext(), "test_");
        mTestContext = getInstrumentation().getContext();
        TestUtils.clearApplicationState(mTargetContext);
        TestUtils.resetEventBus();
    }

    public void testGetCommentEqualTo1024K() {
        createAndGetComment(1024 * 1024);
    }

    public void testGetCommentEqualTo2096550() {
        createAndGetComment(2096550);  // 1024 * 1024 * 2 - 603
    }

    public void testGetCommentEqualTo2096549() {
        createAndGetComment(2096549); // 1024 * 1024 * 2 - 602
    }

    public void testGetCommentEqualTo2048K() {
        createAndGetComment(1024 * 1024 * 2);
    }

    private void createAndGetComment(int commentLength) {
        // Load a sample DB and inject it into WordPress.wpdb
        TestUtils.loadDBFromDump(mTargetContext, mTestContext, "taliwutt-blogs-sample.sql");

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < commentLength; ++i) {
            sb.append('a');
        }
        Comment bigComment = new Comment(0,
                1,
                "author",
                "0",
                sb.toString(),
                "approve",
                "arst",
                "http://mop.com",
                "mop@mop.com",
                "");
        CommentTable.addComment(0, bigComment);
        CommentTable.getCommentsForBlog(0);
    }
}