This repository has been archived by the owner on Apr 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add tests for hotspotInfo() and generateQRBitMap() of QRCodeUtils
- Loading branch information
1 parent
6d03204
commit f616549
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
skunkworks_crow/src/test/java/org/odk/share/utilities/QRCodeUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.odk.share.utilities; | ||
|
||
import android.graphics.Bitmap; | ||
|
||
import com.google.zxing.WriterException; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
@RunWith(RobolectricTestRunner.class) | ||
public class QRCodeUtilsTest { | ||
|
||
/** | ||
* {@link Test} create Hotspot Info of {@link QRCodeUtils} | ||
*/ | ||
@Test | ||
public void createHotspotInfoTest() throws JSONException { | ||
String ssid = "DeviceSSID"; | ||
int port = 3; | ||
String password = "password"; | ||
String hotspotInfo = QRCodeUtils.createHotspotInfo(ssid, port, password); | ||
JSONObject hotspotInfoJson = new JSONObject(hotspotInfo); | ||
assertTrue(hotspotInfoJson.get(QRCodeUtils.SSID).equals(ssid)); | ||
assertTrue(hotspotInfoJson.getInt(QRCodeUtils.PORT) == port); | ||
assertTrue(hotspotInfoJson.getBoolean(QRCodeUtils.PROTECTED)); | ||
assertTrue(hotspotInfoJson.get(QRCodeUtils.PASSWORD).equals(password)); | ||
|
||
password = null; | ||
hotspotInfo = QRCodeUtils.createHotspotInfo(ssid, port, password); | ||
hotspotInfoJson = new JSONObject(hotspotInfo); | ||
assertTrue(hotspotInfoJson.get(QRCodeUtils.SSID).equals(ssid)); | ||
assertFalse(hotspotInfoJson.getBoolean(QRCodeUtils.PROTECTED)); | ||
assertTrue(hotspotInfoJson.getInt(QRCodeUtils.PORT) == port); | ||
} | ||
|
||
/** | ||
* {@link Test} generate QR bitmap of {@link QRCodeUtils} | ||
*/ | ||
@Test | ||
public void generateQRBitMapTest() throws IOException, WriterException { | ||
String data = "Test Bitmap"; | ||
int sideLength = QRCodeUtils.SIDE_LENGTH; | ||
Bitmap bitmap = QRCodeUtils.generateQRBitMap(data, sideLength); | ||
assertTrue(bitmap.getHeight() == sideLength); | ||
assertTrue(bitmap.getWidth() == sideLength); | ||
} | ||
} |