37 Commits

Author SHA1 Message Date
Hans-Christoph Steiner
f538e0da8c add tests for RepoXMLHandler
This is a basic set of tests. These tests should be extended in three ways:
* make sure all of the apps are parsed
* make sure all of the APKs are parsed
* make sure the ProgressListener is called
2014-12-11 13:50:05 +01:00
Daniel Martí
06dd4c8dcb Move F-Droid project into subdir, keeping a root gradle project
Also improved .gitignore a tad
2014-12-09 15:36:07 +01:00
Daniel Martí
216ec24680 Bump target sdk to 21 2014-11-05 21:44:36 +01:00
Hans-Christoph Steiner
be3f7900e8 rename default repo variables for clarity
default_repo_count is not used at all, and the numbering scheme is just a
vestige of that.  This switches all the variables to have clear names of
what they are representing.
2014-07-29 17:49:23 -04:00
Hans-Christoph Steiner
3fef37a5f4 added test of "Master Key"-style exploit based
This does not seem affected, I made a quick and dirty zip with two
index.xml files in it following these instructions:
http://www.saurik.com/id/17

refs #39 https://gitlab.com/fdroid/fdroidclient/issues/39
2014-07-10 13:30:44 -04:00
Hans-Christoph Steiner
0216de670c tests: try everything to find a folder to write to, otherwise skip
The tests of the jar signatures require working on files, but some
emulators make that very difficult.  So try all possible paths for writing
to, and otherwise just skip the tests.
2014-05-20 18:44:47 -04:00
Hans-Christoph Steiner
e782730455 comment out incomplete, failing tests
These are tests that @pserwylo was working on, but hasn't had the time to
complete yet. As far as I know, they have never passed.
2014-05-20 18:44:47 -04:00
Hans-Christoph Steiner
584152d2fa store "App Label" for Installed Apps, to show in Local Repo setup
Most people are going to know the "label" i.e. the display name rather than
the packageName/id.  So also store the label in the database and make it
accessible via InstalledAppsProvider so SelectLocalAppsFragment can show a
list of friendly names rather than packageNames.
2014-05-07 19:16:45 -04:00
Hans-Christoph Steiner
f483630e02 store files for tests in the fdroid cache
For some reason, on some emulators, it is failing to find a place to write
the test index files.  But on most setups, it works fine.  So instead try
writing the files to the cacheDir of FDroid itself rather than the test app
2014-05-01 21:44:27 -04:00
Hans-Christoph Steiner
8395472f8d test index.jar signature checking
I got scared by seeing the Android docs' version of JarFile.getInputStream,
which didn't mention SecurityException or the signature checking. But it
seems that even tho its not in the Android docs, Android implements it the
same as Java does.  It is good to have these tests in place anyhow, since
this is an essential piece of the security process of FDroid.

* http://docs.oracle.com/javase/6/docs/api/java/util/jar/JarFile.html#getInputStream(java.util.zip.ZipEntry)
* https://developer.android.com/reference/java/util/jar/JarFile.html#getInputStream(java.util.zip.ZipEntry)

refs #2627 https://dev.guardianproject.info/issues/2627
refs #2959 https://dev.guardianproject.info/issues/2959
2014-05-01 12:44:01 -04:00
Hans-Christoph Steiner
c0166a26f8 include Apache Commons IO in test project for easy file operations 2014-05-01 12:44:00 -04:00
Hans-Christoph Steiner
1018cad3b4 Utils tests: formatFingerprint() and calcFingerprint(String)
Prevent another stupid bug like what is fixed by commit
5ff177cd1884ed61def491a813363f96c5de628a

refs #2959 https://dev.guardianproject.info/issues/2959
2014-04-28 11:59:36 -04:00
Peter Serwylo
71db322b6d Don't implement 'update' for installed apps, use replace (Fixes #14)
There were some weird edge cases that couldn't quite be pinned down,
whereby installing an app would result in a unique key violation being
hit. One example was when somebody was installing an apk from a file
manager. It seems that this doesn't trigger a PACKAGE_CHANGED, but
rather a PACKAGE_INSTALLED. The end result is that it attempts to insert
a record that already exists in the installed apps table. Because we
have a unique key constraing on the appId, it breaks.

This commit changes the way that we insert installed app details.
Instead of inserting some times, and updating other times, we always
insert. If we hit a unique key violation, the row is deleted, and then
the new values are reinserted.
2014-04-24 13:07:16 +09:30
Peter Serwylo
4e24050760 Adding our own cache of currently installed apks in the database.
Previously the data was not stored anywhere, and each time we wanted
to know about all installed apps, we built a ridiculously long SQL
query. The query had essentially one "OR" clause for each installed
app. To make matters worse, it also required one parameter for each
of these, so we could bind the installed app name to a "?" in the query.
SQL has a limit of (usually) 999 parameters which can be provided to
a query, which meant it would fall over if the user had more than
1000 apps installed.

This change introduces a new table called "fdroid_installedApps".
It is initialized on first run, by iterating over the installed apps
as given by the PackageManager. It is subsequenty kept up to date
by a set of BroadcastReceivers, which listen for apps being
uninstalled/installed/upgraded.

It also includes tests to verify that queries of installed apps,
when there are more than 1000 apps installed, don't break.

Finally, tests are also now able to to insert into providers other
than the one under test. This is due to the fact that the providers
often join onto tables managed by other providers.
2014-04-20 16:50:22 +09:30
Peter Serwylo
8c6ce67100 Added test for "ApkProvider.delete(..., List<Apk>)"
This was explicitly not-allowed previously, and so there was a
test that ensured it threw an exception when attempted on the
ApkProvider. However I implemented it for another feature, but
forgot to change the tests. Now the test no longer tests for
an exception. Rather, it properly tests for the correct execution
of the method.
2014-04-12 09:25:26 +00:00
Hans-Christoph Steiner
d813f1ec17 run JUnit tests using android-junit-report to get XML output
Jenkins needs some kind of report from the JUnit tests in order to tell
whether the tests succeeded or not.  android-junit-report is a library to do
exactly that.  With this setup, Jenkins should now successfully understand the
status of the JUnit tests, where before it just ran them and ignored the
results
2014-04-11 14:10:26 -04:00
Peter Serwylo
3ebad383d6 Refactored the recent MR for dynamicly adding default repos.
The idea was good: reduce the amount of copied/pasted code
where ContentValues were initialized, populated, then inserted.
I've kept the idea, by putting it in its own method which is
called twice. But the resources are not loaded dynamically any
more. This is so that the compiler will be able to pick up if
we reference a missing resource. Also, I took the opportunity
to replace the field name string literals with references to
RepoProvider.DataColumns.* constants.

Finally, changed the tests around because now we need to
have the "getInteger()" call mocked in resources correctly
(for priority/inUse).
2014-03-23 22:31:06 +11:00
Peter Serwylo
9fd8da42a1 Adding test coverage for "AppProvider.Helper.findIgnored()"
Also added tests for canAndWantToUpdate() while I was at it.
2014-03-06 23:31:26 +11:00
Daniel Martí
2c9d8ab7fc Merge commit 'refs/merge-requests/66' of gitorious.org:f-droid/fdroidclient
Conflicts:
	test/src/org/fdroid/fdroid/ApkProviderTest.java
2014-02-20 08:00:12 +01:00
Peter Serwylo
2dcd87cd41 Almost 100% test coverage of ApkProvider and ApkProvider.Helper
Removed unused code from ApkProvider.Helper, made it throw proper
exceptions when trying unsupported operations. Refactored tests
a little bit to facilitate separate test cases for the provider
and its helper.
2014-02-20 16:13:37 +11:00
Hans-Christoph Steiner
888d28aed6 @Override decorator on every method that overrides
This marks a method as overriding another method, and makes sure that it
matches the signature of the method it is supposed to be overriding,
otherwise it gives a warning.

Its a bit verbose, but can catch mistakes and save time. And the default
Android profile for Eclipse always adds them automatically...
2014-02-19 20:06:05 -05:00
Hans-Christoph Steiner
301ac10515 remove trailing white space... 2014-02-19 19:59:31 -05:00
Hans-Christoph Steiner
5d828e2341 remove all unused imports
This reduces the number of warnings so that we can see the useful ones!
2014-02-19 19:52:36 -05:00
Hans-Christoph Steiner
09f3e8b004 forgot to include the .project Eclipse file for the test project
Include the reusable Eclipse files (.project and .classpath).
2014-02-18 19:04:05 -05:00
Daniel Martí
226003d38d Git automatic indenting fix 2014-02-19 00:19:05 +01:00
Peter Serwylo
5877af55ae Merge branch 'master' into improvements/apk-tests
Conflicts:
	test/src/org/fdroid/fdroid/AppProviderTest.java
2014-02-19 09:38:40 +11:00
Peter Serwylo
a797e43178 Test apk insert more comprehensivly. 2014-02-19 09:32:54 +11:00
Peter Serwylo
4860e06af3 Improved apk tests (test deleting). 2014-02-19 08:12:21 +11:00
Peter Serwylo
85f3232de0 Started implementing ApkProvider tests.
Refactored a couple of common things from AppProviderTest to either
FDroidProviderTest (baseclass) or TestUtils (static methods) where
relevant.
2014-02-18 02:52:02 +11:00
Peter Serwylo
43f8ea0814 Added category tests.
This will be useful when somebody wants to move categories from a comma
separated string in the app table, to a separate table all together.
2014-02-16 21:54:50 +11:00
Daniel Martí
41b5797307 Automatic tab fixing 2014-02-16 02:48:22 +01:00
Hans-Christoph Steiner
739ecfdea3 commit Eclipse project files to make it easier for others to start
Having the pre-configured Eclipse files in git will make it easier for
other people to work with FDroid in Eclipse, and should not affect anything
else. The key files are .classpath and .project.  The .settings/ folder is
for user-specific settings, so its ignored.
2014-02-14 23:07:49 -05:00
Daniel Martí
c99cf93c8b Test projects can't have --name it seems 2014-02-14 09:18:21 +01:00
Daniel Martí
cf1519f792 Add eclipse files to gitignore 2014-02-14 09:16:18 +01:00
Hans-Christoph Steiner
9871ad0f01 ant-prepare.sh: also set up test suite, should not affect normal ant builds
This adds the command to update the embedded Android Test Project, so that
it can be run using `cd test/; ant clean emma debug install test`

It also changes -p to --path just to make things a little easier to read.
2014-02-13 21:53:52 -05:00
Hans-Christoph Steiner
113ae202b7 include Eclipse project for the embedded Android Test Project
This should make it easier for some people get started with the tests.
2014-02-13 21:51:29 -05:00
Peter Serwylo
da8e41249b Removed DB, implemented AppProvider.
Yay!

As expected, a lot of the stuff in DB class is due to UpdateService
requiring it to process the downloaded indexes and insert data into
the database. Thus, this change is about removing that stuff from
the DB class and migrating to ContentProviders.

This required a bit of a change to the way that UpdateService decides
what to do with the data from indexes, but I hope it will make
understanding and changing UpdateService easier in the long term.
For example, it used to read the app details from database, then
if a repo wasn't updated (due to unchanged index) then it would take
the app details for that repo from the list of apps, and re-update
the database (or something like that).

Now, it has been refactored into the following methods:
 * updateOrInsertApps(appsToUpdate);
 * updateOrInsertApks(apksToUpdate);
 * removeApksFromRepos(disabledRepos);
 * removeApksNoLongerInRepo(appsToUpdate, updatedRepos);
 * removeAppsWithoutApks();
 * and probably some others...
Which hopefully are self-explanitory.

The recent change to implement single repo updates was re-implemented
with in light of the methods above. The interface to UpdateService for
scheduling a single repo update is the same as it was before, but
the implementation is completely different. Still works though.

Using batch content provider operations for repo updates,
but they suffer from the problem of not all being under the same
transaction, so if an insert/update stuffs up half way through, we
are left with only half of the update being complete. In the future,
if there is some way to implement notifications from the content provider's
applyBatch method, then we can do it all in the one transaction, and
still have notifications. Currently we break it into several calls
to applyBatch (and hence several transactions) to inform the user
of the progress.

Also adding the beginnings of some tests for AppProvider. In the future, I'll
work on adding better coverage, including instrumentation to test UI features.

==========================
Below is a list of many of the minor changes that also happened along the way
==========================

Make "Can update" tab stay up to date using content observer, rather
than manually deciding when to refresh the tab label as before.

The installed app list is now cached in Utils, because it is invoked
quite a few times, especially when rendering the app lists. The cache is
invalidated when PackageReceiver is notified of new apps.

The content providers don't notify changes if we are in batch mode.
I've left the notification at the end of the batch updates as the
responsibility of the UpdateService. However, it would be nice if this
was somehow handled by the content, as they are really the ones who
should worry about it.

Made curVersion, curVercode and curApk work with providers.
This was done by removing curApk (otherwise we'd need to query the db each
time we fetched one app to get a reference to that apk (resulting in hundreds
of queries). Instead, UpdateService now calculates curVercode and curVersion
and saves them to the database. We then use these where possible. If we really
need curApk (because we want info other than its version and code) we still have
the option of ApkProvider.Helper.find(app.id, app.curVercode). I considered
putting this inside the app value object, e.g. in getCurApk() but thought
better of it as it will likely result in people invoking it all the time,
without realising it causes a DB query.

incompatibleReasons required a minor UI tweak, removing the "min sdk"
ui element from the Apk list. It is replaced by the "Requires: %s" view
(which only appears when the app is incompatible). In the process, and in
response to some feedback from mvdan, I left the min sdk in there, but
only made it show when in "expert mode", just like the architecture.

In order to make the "installed apps" query work under test conditions,
needed to change the way the InstalledApkCache be replaceable with a
mock object.

Pause UIL loading on fast scroll of list, as the list was very choppy for
some reason.

Re-added "Last repo scan" info to the Manage Repo list view.

Fixed up some misc TODO's, removed some unused/empty functions.
2014-02-08 11:29:59 +11:00