Skip to content

Commit

Permalink
New tests project, + legacy data structures for testing importing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Su committed May 11, 2010
1 parent 288a7a4 commit 5ad2de1
Show file tree
Hide file tree
Showing 59 changed files with 7,487 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="src" path="plugin-src"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry combineaccessrules="false" kind="src" path="/astrid-3.x"/>
<classpathentry kind="output" path="ecbuild"/>
</classpath>
33 changes: 33 additions & 0 deletions tests/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>astrid-3.x-tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
270 changes: 270 additions & 0 deletions tests/.settings/org.eclipse.jdt.core.prefs

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions tests/.settings/org.eclipse.jdt.ui.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Sat Aug 22 23:48:16 PDT 2009
cleanup_settings_version=2
eclipse.preferences.version=1
formatter_profile=_Astrid
formatter_settings_version=11
23 changes: 23 additions & 0 deletions tests/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

# We only want this apk build for tests.
LOCAL_MODULE_TAGS := tests

LOCAL_JAVA_LIBRARIES := android.test.runner

# Include all test java files.
LOCAL_SRC_FILES := $(call all-java-files-under, src)

# Notice that we don't have to include the src files of ApiDemos because, by
# running the tests using an instrumentation targeting ApiDemos, we
# automatically get all of its classes loaded into our environment.

LOCAL_PACKAGE_NAME := AstridTests

LOCAL_INSTRUMENTATION_FOR := Astrid

LOCAL_SDK_VERSION := current

include $(BUILD_PACKAGE)

25 changes: 25 additions & 0 deletions tests/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.todoroo.astrid.tests"
android:versionCode="1"
android:versionName="1.0">

<uses-sdk android:minSdkVersion="3" />

<!-- We add an application tag here just so that we can indicate that
this package needs to link against the android.test library,
which is needed when building test cases. -->
<application>
<uses-library android:name="android.test.runner" />
</application>

<!--
This declares that this application uses the instrumentation test runner targeting
the package of the parent app. To run the tests use the command:
"adb shell am instrument -w com.xxx.xxx.tests/android.test.InstrumentationTestRunner"
-->
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.todoroo.astrid"
android:label="Tests for Astrid"/>
</manifest>
15 changes: 15 additions & 0 deletions tests/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file is used to override default values used by the Ant build system.
#
# This file must be checked in Version Control Systems, as it is
# integral to the build system of your project.

# The name of your application package as defined in the manifest.
# Used by the 'uninstall' rule.
#application-package=com.example.myproject

# The name of the source folder.
#source-folder=src

# The name of the output folder.
#out-folder=bin

61 changes: 61 additions & 0 deletions tests/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Main" default="help">

<!-- The local.properties file is created and updated by the 'android' tool.
It contain the path to the SDK. It should *NOT* be checked in in Version
Control Systems. -->
<property file="local.properties"/>

<!-- The build.properties file can be created by you and is never touched
by the 'android' tool. This is the place to change some of the default property values
used by the Ant rules.
Here are some properties you may want to change/update:
application-package
the name of your application package as defined in the manifest. Used by the
'uninstall' rule.
source-folder
the name of the source folder. Default is 'src'.
out-folder
the name of the output folder. Default is 'bin'.
Properties related to the SDK location or the project target should be updated
using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your application and
should be checked in in Version Control Systems.
-->
<property file="build.properties"/>

<!-- The default.properties file is created and updated by the 'android' tool, as well
as ADT.
This file is an integral part of the build system for your application and
should be checked in in Version Control Systems. -->
<property file="default.properties"/>

<!-- Custom Android task to deal with the project target, and import the proper rules.
This requires ant 1.6.0 or above. -->
<path id="android.antlibs">
<pathelement path="${sdk-location}/tools/lib/anttasks.jar" />
<pathelement path="${sdk-location}/tools/lib/sdklib.jar" />
<pathelement path="${sdk-location}/tools/lib/androidprefs.jar" />
<pathelement path="${sdk-location}/tools/lib/apkbuilder.jar" />
<pathelement path="${sdk-location}/tools/lib/jarutils.jar" />
</path>

<taskdef name="setup"
classname="com.android.ant.SetupTask"
classpathref="android.antlibs"/>

<!-- Execute the Android Setup task that will setup some properties specific to the target,
and import the rules files.
To customize the rules, copy/paste them below the task, and disable import by setting
the import attribute to false:
<setup import="false" />
This will ensure that the properties are setup correctly but that your customized
targets are used.
-->
<setup />
</project>
13 changes: 13 additions & 0 deletions tests/default.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-4
130 changes: 130 additions & 0 deletions tests/plugin-src/com/todoroo/astrid/reminders/AlarmReceiverTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package com.todoroo.astrid.reminders;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.Intent;

import com.todoroo.andlib.test.utility.DateUtilities;
import com.todoroo.astrid.model.Task;

public class AlarmReceiverTests extends PluginTestCase {

/** simple test of task at deadline */
public void testDeadlineReminder() {
Task task = new Task();
task.setValue(Task.TITLE, "poop");
task.setValue(Task.DUE_DATE, DateUtilities.now());

long id = createTask(task, null);
Intent alarmIntent = new Intent();
alarmIntent.putExtra(AlarmReceiver.TOKEN_TASK_ID, id);
alarmIntent.putExtra(AlarmReceiver.TOKEN_IS_DEADLINE, true);
alarmIntent.putExtra(AlarmReceiver.TOKEN_IS_ALARMCLOCK, false);

AlarmReceiver rx = new AlarmReceiver();
AssertiveNotificationManager nm = new AssertiveNotificationManager(getContext());
AlarmReceiver.notificationManager = nm;
rx.onReceive(getContext(), alarmIntent);
nm.assertNotified();
}

/** task at deadline, except hidden. no notification should sound */
public void testDeadlineReminderExceptHidden() {
Task task = new Task();
task.setValue(Task.TITLE, "poop");
task.setValue(Task.DUE_DATE, DateUtilities.now());
task.setValue(Task.HIDDEN_UNTIL, DateUtilities.now() + 100);

long id = createTask(task, null);
Intent alarmIntent = new Intent();
alarmIntent.putExtra(AlarmReceiver.TOKEN_TASK_ID, id);
alarmIntent.putExtra(AlarmReceiver.TOKEN_IS_DEADLINE, true);
alarmIntent.putExtra(AlarmReceiver.TOKEN_IS_ALARMCLOCK, false);

AlarmReceiver rx = new AlarmReceiver();
AssertiveNotificationManager nm = new AssertiveNotificationManager(getContext());
AlarmReceiver.notificationManager = nm;
rx.onReceive(getContext(), alarmIntent);
nm.assertNotNotified();
}

/** task upcoming */
public void testUpcomingReminder() {
Task task = new Task();
task.setValue(Task.TITLE, "poop");
task.setValue(Task.DUE_DATE, DateUtilities.now() + 100);

long id = createTask(task, null);
Intent alarmIntent = new Intent();
alarmIntent.putExtra(AlarmReceiver.TOKEN_TASK_ID, id);
alarmIntent.putExtra(AlarmReceiver.TOKEN_IS_DEADLINE, false);
alarmIntent.putExtra(AlarmReceiver.TOKEN_IS_ALARMCLOCK, false);

AlarmReceiver rx = new AlarmReceiver();
AssertiveNotificationManager nm = new AssertiveNotificationManager(getContext());
AlarmReceiver.notificationManager = nm;
rx.onReceive(getContext(), alarmIntent);
nm.assertNotified();
}

/** task overdue */
public void testOverdueReminder() {
Task task = new Task();
task.setValue(Task.TITLE, "poop");
task.setValue(Task.DUE_DATE, DateUtilities.now() - 100);

long id = createTask(task, null);
Intent alarmIntent = new Intent();
alarmIntent.putExtra(AlarmReceiver.TOKEN_TASK_ID, id);
alarmIntent.putExtra(AlarmReceiver.TOKEN_IS_DEADLINE, false);
alarmIntent.putExtra(AlarmReceiver.TOKEN_IS_ALARMCLOCK, false);

AlarmReceiver rx = new AlarmReceiver();
AssertiveNotificationManager nm = new AssertiveNotificationManager(getContext());
AlarmReceiver.notificationManager = nm;
rx.onReceive(getContext(), alarmIntent);
nm.assertNotified();
}

/** task alarm clock */
public void testAlarmClock() {
Task task = new Task();
task.setValue(Task.TITLE, "poop");
task.setValue(Task.DUE_DATE, DateUtilities.now());

long id = createTask(task, null);
Intent alarmIntent = new Intent();
alarmIntent.putExtra(AlarmReceiver.TOKEN_TASK_ID, id);
alarmIntent.putExtra(AlarmReceiver.TOKEN_IS_DEADLINE, true);
alarmIntent.putExtra(AlarmReceiver.TOKEN_IS_ALARMCLOCK, true);

AlarmReceiver rx = new AlarmReceiver();
AssertiveNotificationManager nm = new AssertiveNotificationManager(getContext());
AlarmReceiver.notificationManager = nm;
rx.onReceive(getContext(), alarmIntent);
nm.assertNotified();
assertTrue((nm.getNotification().flags & Notification.FLAG_INSISTENT) > 0);
}

/** test the intent that the alarm receiver creates */
public void testOpenIntent() throws Exception {
Task task = new Task();
task.setValue(Task.TITLE, "poop");
task.setValue(Task.DUE_DATE, DateUtilities.now());

long id = createTask(task, null);
Intent alarmIntent = new Intent();
alarmIntent.putExtra(AlarmReceiver.TOKEN_TASK_ID, id);
alarmIntent.putExtra(AlarmReceiver.TOKEN_IS_DEADLINE, true);
alarmIntent.putExtra(AlarmReceiver.TOKEN_IS_ALARMCLOCK, false);

AlarmReceiver rx = new AlarmReceiver();
AssertiveNotificationManager nm = new AssertiveNotificationManager(getContext());
AlarmReceiver.notificationManager = nm;
rx.onReceive(getContext(), alarmIntent);
nm.assertNotified();

PendingIntent intent = nm.getNotification().contentIntent;
intent.send();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.todoroo.astrid.reminders;

import android.app.Notification;
import android.content.Context;

import com.todoroo.andlib.service.NotificationManager.AndroidNotificationManager;

/**
* Notification manager that provides notifications and adds an
* extra method for verification.
*
* @author timsu
*
*/
public class AssertiveNotificationManager extends AndroidNotificationManager {

Notification notification = null;

public AssertiveNotificationManager(Context context) {
super(context);

}

@Override
public void notify(int id, Notification notification) {
super.notify(id, notification);
this.notification = notification;
}

public void assertNotified() {
if(notification == null)
throw new AssertionError("Notification was not triggered");
}

public void assertNotNotified() {
if(notification != null)
throw new AssertionError("Notification was triggered");
}

public Notification getNotification() {
return notification;
}

public void clear() {
notification = null;
}
}
Loading

0 comments on commit 5ad2de1

Please sign in to comment.