Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
forrestguice committed Sep 20, 2022
1 parent 1450b39 commit ce2ec6d
Showing 1 changed file with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,24 @@
import android.content.ContentValues;
import android.content.Context;

import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.os.Build;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.RenamingDelegatingContext;

import com.forrestguice.suntimeswidget.R;
import com.forrestguice.suntimeswidget.calculator.core.Location;
import com.forrestguice.suntimeswidget.settings.AppSettings;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.HashMap;
import java.util.Locale;

import static com.forrestguice.suntimeswidget.getfix.GetFixDatabaseAdapter.KEY_PLACE_ALTITUDE;
import static com.forrestguice.suntimeswidget.getfix.GetFixDatabaseAdapter.KEY_PLACE_COMMENT;
Expand Down Expand Up @@ -83,6 +89,67 @@ public void test_addPlace()
db.close();
}

@Test
public void test_addDefaults()
{
int count = 0;
db.open();
for (Locale locale : Locale.getAvailableLocales())
{
Configuration config = new Configuration(mockContext.getResources().getConfiguration());
config.setLocale(locale);

Resources resources = mockContext.createConfigurationContext(config).getResources();
String label = resources.getString(R.string.default_location_label);
String lat = resources.getString(R.string.default_location_latitude);
String lon = resources.getString(R.string.default_location_longitude);
String alt = resources.getString(R.string.default_location_altitude);
Location location = new Location(label, lat, lon, alt);

long id = db.addPlace(location);
assertTrue("ID should be >= 0 (was " + id + ")", id != -1);
count++;

int n = db.getPlaceCount();
assertTrue("database should contain " + count + " entry (contained " + n + ")", db.getPlaceCount() == count);
}
db.close();
}

@Test
public void test_addLastFix()
{
int count = 0;
db.open();
for (Locale locale : Locale.getAvailableLocales())
{
Configuration config = new Configuration(mockContext.getResources().getConfiguration());
config.setLocale(locale);

Resources resources = mockContext.createConfigurationContext(config).getResources();
String lat = resources.getString(R.string.default_location_latitude);
String lon = resources.getString(R.string.default_location_longitude);
String alt = resources.getString(R.string.default_location_altitude);

Location[] locations = new Location[] {
new Location(resources.getString(R.string.gps_lastfix_title_found), lat, lon, alt),
new Location(resources.getString(R.string.gps_lastfix_title_searching), lat, lon, alt),
new Location(resources.getString(R.string.gps_lastfix_title_set), lat, lon, alt)
};

for (Location location : locations)
{
long id = db.addPlace(location);
assertTrue("ID should be >= 0 (was " + id + ")", id != -1);
count++;

int n = db.getPlaceCount();
assertTrue("database should contain " + count + " entry (contained " + n + ")", db.getPlaceCount() == count);
}
}
db.close();
}

@Test
public void test_addPlaceCSV()
{
Expand Down

0 comments on commit ce2ec6d

Please sign in to comment.