// Path: app/src/main/java/org/pquery/util/Util.java
// public class Util {
// 
//     /**
//      * Produce a human download progress string given bytes downloaded and total
//      * e.g 14/100 KiB
//      */
//     public static String humanDownloadCounter(int bytesDownloaded, int expected) {
//         StringBuffer ret = new StringBuffer();
// 
//         ret.append(bytesDownloaded / 1024);
//         if (expected > 0)
//             ret.append("/" + expected / 1024);
//         ret.append(" KiB");
// 
//         return ret.toString();
//     }
// 
//     private static final String reservedCharsRegExp = "[|\\\\?*<\":>+\\[\\]/']";
// 
//     /**
//      * Try to create a legal filename from what user entered
//      * <p/>
//      * Strip illegal characters.
//      * If that ends up with an empty filename, use a default
//      */
//     public static String sanitizeFileName(String name) {
//         name = name.replaceAll(reservedCharsRegExp, "");
//         if (name.length() == 0)
//             name = "pocketquery";
//         return name;
//     }
// 
//     /**
//      * Create a sane, unique file
//      * Strips illegal characters and adds numbers on end to make unique (if necessary)
//      */
//     public static File getUniqueFile(String path, String name, String extension) {
// 
//         name = sanitizeFileName(name);
// 
//         int i = 0;
//         File file = new File(path, name + "." + extension);
//         while (file.exists()) {
//             // Try to add a number at end to make unique
//             i++;
//             file = new File(path, name + "(" + i + ")." + extension);
//         }
//         return file;
//     }
// 
//     /**
//      * Create a sane, unique file
//      * Strips illegal characters and adds numbers on end to make unique (if necessary)
//      */
//     public static File getUniqueFile(String path, String name) {
//         return getUniqueFile(path, removeExtension(name), "zip");
//     }
// 
//     /**
//      * Extract extension from a file
//      */
//     public static String removeExtension(String s) {
//         String ret = s;
//         int i = s.lastIndexOf('.');
// 
//         if (i > 0 && i < s.length() - 1) {
//             ret = s.substring(0, i);
//         }
//         return ret;
//     }
// 
//     public static String getDefaultDownloadDirectory(Context cxt) {
// 
//         String dir;
// 
//         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M ) {
//             // Old behaviour that I am not changing
//             dir = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Download";
//         } else {
//             // New android 6
//             // Default to the (pretty rubbish) directory we will always be able to write to
//             // without asking for more permissions
//            dir = cxt.getFilesDir().getAbsolutePath();
//         }
// 
//         return dir;
//     }
// 
//     /**
//      * Read a 'Reader' (e.g. FileReader), into a String
//      */
//     public static String readerIntoString(Reader read) throws IOException {
//         StringBuffer out = new StringBuffer();
//         BufferedReader buffreader = new BufferedReader(read);
// 
//         String line = buffreader.readLine();
//         while (line != null) {
//             out.append(line);
//             out.append("\r\n");     // 'readLine' strips newlines so have to put back on
//             line = buffreader.readLine();
//         }
//         return out.toString();
//     }
// 
//     public static String inputStreamIntoString(InputStream streamIn) throws IOException {
//         return readerIntoString(new InputStreamReader(streamIn, "utf8"));
//     }
// 
// 
//     public static Drawable toGrey(Resources res, int resource) {
// 
//         Drawable draw = res.getDrawable(resource);
// 
//         Bitmap b = ((BitmapDrawable) draw).getBitmap().copy(Config.ARGB_8888, true);
// 
//         //Bitmap copy = src.copy(Config.ARGB_8888, true);
// 
//         for (int x = 0; x < b.getWidth(); x++)
//             for (int y = 0; y < b.getHeight(); y++) {
//                 int color = b.getPixel(x, y);
//                 int newColor = Color.argb(Color.alpha(color) / 3, Color.red(color), Color.green(color), Color.blue(color));
//                 b.setPixel(x, y, newColor);
// 
//             }
// 
//         Drawable greyDrawable = new BitmapDrawable(res, b);
// 
//         return greyDrawable;
//     }
// }


import android.test.AndroidTestCase;
import net.htmlparser.jericho.FormFields;
import org.pquery.util.Util;
import org.pquery.webdriver.parser.GeocachingPage.ParseException;
import java.io.IOException;
import java.io.InputStream;

package org.pquery.webdriver.parser;





public class GeocachingPageTest extends AndroidTestCase {

    private GeocachingPage simple;
    private GeocachingPage createNewPocketQuery;
    private GeocachingPage createNewPocketQueryLoggedOut;
    private GeocachingPage createNewPocketQueryNonPremium;

    @Override
    protected void setUp() throws Exception {

        simple = new GeocachingPage(loadFromResource("simple_form.htm"));
        createNewPocketQuery = new GeocachingPage(loadFromResource("create_new_pocket_query.htm"));
        createNewPocketQueryLoggedOut = new GeocachingPage(loadFromResource("create_new_pocket_query_logged_out.htm"));
        createNewPocketQueryNonPremium = new GeocachingPage(loadFromResource("create_new_pocket_query_non_premium.htm"));
    }

    private String loadFromResource(String name) throws IOException {
        InputStream in = getClass().getClassLoader().getResourceAsStream("res/raw/" + name);
        assertNotNull(in);

// Path: app/src/main/java/org/pquery/util/Util.java
// public class Util {
// 
//     /**
//      * Produce a human download progress string given bytes downloaded and total
//      * e.g 14/100 KiB
//      */
//     public static String humanDownloadCounter(int bytesDownloaded, int expected) {
//         StringBuffer ret = new StringBuffer();
// 
//         ret.append(bytesDownloaded / 1024);
//         if (expected > 0)
//             ret.append("/" + expected / 1024);
//         ret.append(" KiB");
// 
//         return ret.toString();
//     }
// 
//     private static final String reservedCharsRegExp = "[|\\\\?*<\":>+\\[\\]/']";
// 
//     /**
//      * Try to create a legal filename from what user entered
//      * <p/>
//      * Strip illegal characters.
//      * If that ends up with an empty filename, use a default
//      */
//     public static String sanitizeFileName(String name) {
//         name = name.replaceAll(reservedCharsRegExp, "");
//         if (name.length() == 0)
//             name = "pocketquery";
//         return name;
//     }
// 
//     /**
//      * Create a sane, unique file
//      * Strips illegal characters and adds numbers on end to make unique (if necessary)
//      */
//     public static File getUniqueFile(String path, String name, String extension) {
// 
//         name = sanitizeFileName(name);
// 
//         int i = 0;
//         File file = new File(path, name + "." + extension);
//         while (file.exists()) {
//             // Try to add a number at end to make unique
//             i++;
//             file = new File(path, name + "(" + i + ")." + extension);
//         }
//         return file;
//     }
// 
//     /**
//      * Create a sane, unique file
//      * Strips illegal characters and adds numbers on end to make unique (if necessary)
//      */
//     public static File getUniqueFile(String path, String name) {
//         return getUniqueFile(path, removeExtension(name), "zip");
//     }
// 
//     /**
//      * Extract extension from a file
//      */
//     public static String removeExtension(String s) {
//         String ret = s;
//         int i = s.lastIndexOf('.');
// 
//         if (i > 0 && i < s.length() - 1) {
//             ret = s.substring(0, i);
//         }
//         return ret;
//     }
// 
//     public static String getDefaultDownloadDirectory(Context cxt) {
// 
//         String dir;
// 
//         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M ) {
//             // Old behaviour that I am not changing
//             dir = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Download";
//         } else {
//             // New android 6
//             // Default to the (pretty rubbish) directory we will always be able to write to
//             // without asking for more permissions
//            dir = cxt.getFilesDir().getAbsolutePath();
//         }
// 
//         return dir;
//     }
// 
//     /**
//      * Read a 'Reader' (e.g. FileReader), into a String
//      */
//     public static String readerIntoString(Reader read) throws IOException {
//         StringBuffer out = new StringBuffer();
//         BufferedReader buffreader = new BufferedReader(read);
// 
//         String line = buffreader.readLine();
//         while (line != null) {
//             out.append(line);
//             out.append("\r\n");     // 'readLine' strips newlines so have to put back on
//             line = buffreader.readLine();
//         }
//         return out.toString();
//     }
// 
//     public static String inputStreamIntoString(InputStream streamIn) throws IOException {
//         return readerIntoString(new InputStreamReader(streamIn, "utf8"));
//     }
// 
// 
//     public static Drawable toGrey(Resources res, int resource) {
// 
//         Drawable draw = res.getDrawable(resource);
// 
//         Bitmap b = ((BitmapDrawable) draw).getBitmap().copy(Config.ARGB_8888, true);
// 
//         //Bitmap copy = src.copy(Config.ARGB_8888, true);
// 
//         for (int x = 0; x < b.getWidth(); x++)
//             for (int y = 0; y < b.getHeight(); y++) {
//                 int color = b.getPixel(x, y);
//                 int newColor = Color.argb(Color.alpha(color) / 3, Color.red(color), Color.green(color), Color.blue(color));
//                 b.setPixel(x, y, newColor);
// 
//             }
// 
//         Drawable greyDrawable = new BitmapDrawable(res, b);
// 
//         return greyDrawable;
//     }
// }


// Path: app/src/androidTest/java/org/pquery/webdriver/parser/GeocachingPageTest.java
import android.test.AndroidTestCase;
import net.htmlparser.jericho.FormFields;
import org.pquery.util.Util;
import org.pquery.webdriver.parser.GeocachingPage.ParseException;
import java.io.IOException;
import java.io.InputStream;

package org.pquery.webdriver.parser;





public class GeocachingPageTest extends AndroidTestCase {

    private GeocachingPage simple;
    private GeocachingPage createNewPocketQuery;
    private GeocachingPage createNewPocketQueryLoggedOut;
    private GeocachingPage createNewPocketQueryNonPremium;

    @Override
    protected void setUp() throws Exception {

        simple = new GeocachingPage(loadFromResource("simple_form.htm"));
        createNewPocketQuery = new GeocachingPage(loadFromResource("create_new_pocket_query.htm"));
        createNewPocketQueryLoggedOut = new GeocachingPage(loadFromResource("create_new_pocket_query_logged_out.htm"));
        createNewPocketQueryNonPremium = new GeocachingPage(loadFromResource("create_new_pocket_query_non_premium.htm"));
    }

    private String loadFromResource(String name) throws IOException {
        InputStream in = getClass().getClassLoader().getResourceAsStream("res/raw/" + name);
        assertNotNull(in);

        String ret = Util.inputStreamIntoString(in);
