Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
appinventor-sources
Commits
8bce6ff5
Commit
8bce6ff5
authored
Sep 19, 2019
by
Evan W. Patton
Committed by
Susan Rati Lane
Sep 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement number => InstantInTime coercion (and clean up tests) (#1844)
Change-Id: If46915890381f0b05165804d802281a4b28c174c
parent
28e898d9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
37 deletions
+83
-37
appinventor/buildserver/build.xml
appinventor/buildserver/build.xml
+8
-0
appinventor/buildserver/src/com/google/appinventor/buildserver/resources/runtime.scm
.../com/google/appinventor/buildserver/resources/runtime.scm
+5
-1
appinventor/buildserver/tests/com/google/appinventor/buildserver/YailAndroidTest.java
...s/com/google/appinventor/buildserver/YailAndroidTest.java
+59
-0
appinventor/buildserver/tests/com/google/appinventor/buildserver/YailEvalTest.java
...ests/com/google/appinventor/buildserver/YailEvalTest.java
+10
-35
appinventor/components/src/com/google/appinventor/components/runtime/Clock.java
.../src/com/google/appinventor/components/runtime/Clock.java
+1
-1
No files found.
appinventor/buildserver/build.xml
View file @
8bce6ff5
...
...
@@ -352,11 +352,19 @@
<fileset
dir=
"${run.lib.dir}"
includes=
"*.jar"
/>
<pathelement
location=
"${build.dir}/common/CommonTestUtils.jar"
/>
<pathelement
location=
"${build.dir}/components/AndroidRuntime.jar"
/>
<fileset
dir=
"${build.dir}/components/deps"
includes=
"*.jar"
/>
<pathelement
location=
"${lib.dir}/kawa/kawa-1.11-modified.jar"
/>
<pathelement
location=
"${lib.dir}/guava/guava-14.0.1.jar"
/>
<pathelement
location=
"${lib.dir}/commons-io/commons-io-2.0.1.jar"
/>
<pathelement
location=
"${lib.dir}/json/json.jar"
/>
<pathelement
location=
"${lib.dir}/junit/junit-4.8.2.jar"
/>
<pathelement
location=
"${lib.dir}/junit4/tl4j-junit4-1.1.3.jar"
/>
<pathelement
location=
"${lib.dir}/bouncycastle/bcprov-jdk15on-149.jar"
/>
<pathelement
location=
"${lib.dir}/powermock/cglib-nodep-2.2.jar"
/>
<pathelement
location=
"${lib.dir}/powermock/easymock-3.0.jar"
/>
<pathelement
location=
"${lib.dir}/powermock/javassist-3.18.0-GA.jar"
/>
<pathelement
location=
"${lib.dir}/powermock/objenesis-1.2.jar"
/>
<pathelement
location=
"${lib.dir}/powermock/powermock-easymock-1.4.10-full.jar"
/>
</path>
<path
id=
"BuildServerTests.path"
>
...
...
appinventor/buildserver/src/com/google/appinventor/buildserver/resources/runtime.scm
View file @
8bce6ff5
...
...
@@ -1336,7 +1336,11 @@
(
define
(
coerce-to-instant
arg
)
(
cond
((
instance?
arg
java
.
util
.
Calendar
)
arg
)
(
else
*non-coercible-value*
)))
(
else
(
let
((
as-millis
(
coerce-to-number
arg
)))
(
if
(
number?
as-millis
)
(
com
.
google
.
appinventor
.
components
.
runtime
.
Clock:MakeInstantFromMillis
as-millis
)
*non-coercible-value*
)))))
(
define
(
coerce-to-component
arg
)
(
cond
...
...
appinventor/buildserver/tests/com/google/appinventor/buildserver/YailAndroidTest.java
0 → 100644
View file @
8bce6ff5
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2019 MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
package
com.google.appinventor.buildserver
;
import
com.google.appinventor.common.testutils.TestUtils
;
import
com.google.appinventor.components.runtime.Clock
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
kawa.standard.Scheme
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.powermock.api.easymock.PowerMock
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
@RunWith
(
PowerMockRunner
.
class
)
public
class
YailAndroidTest
{
private
Scheme
scheme
;
private
static
final
String
YAIL_SCHEME_TESTS
=
TestUtils
.
APP_INVENTOR_ROOT_DIR
+
"/buildserver/tests/com/google/appinventor/buildserver/YailEvalTest.scm"
;
@Before
public
void
setUp
()
throws
Exception
{
scheme
=
new
Scheme
();
String
yailRuntimeLibrary
=
Compiler
.
getResource
(
Compiler
.
YAIL_RUNTIME
);
try
{
scheme
.
eval
(
"(load \""
+
yailRuntimeLibrary
+
"\")"
);
scheme
.
eval
(
"(load \""
+
YAIL_SCHEME_TESTS
+
"\")"
);
scheme
.
eval
(
"(set! *testing* #t)"
);
}
catch
(
Exception
e
)
{
throw
e
;
}
catch
(
Throwable
throwable
)
{
throw
new
RuntimeException
(
throwable
);
}
}
@Test
public
void
testFormatDateTime
()
throws
Throwable
{
// Unfortunately, call-component-method requires an actual component, even though
// FormatDateTime method is static. This means we have to mock out a Clock component so that
// method lookup can be performed by Kawa.
Clock
c
=
PowerMock
.
createMock
(
Clock
.
class
);
scheme
.
define
(
"*test-clock*"
,
c
);
String
output
=
scheme
.
eval
(
"(begin (add-to-current-form-environment 'Clock1 *test-clock*)"
+
"(call-component-method 'Clock1 'FormatDateTime"
+
" (*list-for-runtime* 0 \"MM/dd/yyyy hh:mm:ss a\") '(InstantInTime text)))"
)
.
toString
();
Calendar
expected
=
Calendar
.
getInstance
();
expected
.
setTimeInMillis
(
0
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"MM/dd/yyyy hh:mm:ss a"
);
assertEquals
(
sdf
.
format
(
expected
.
getTime
()),
output
);
}
}
appinventor/buildserver/tests/com/google/appinventor/buildserver/YailEvalTest.java
View file @
8bce6ff5
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-201
2
MIT, All rights reserved
// Copyright 2011-201
9
MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
...
...
@@ -8,10 +8,8 @@ package com.google.appinventor.buildserver;
import
com.google.appinventor.common.testutils.TestUtils
;
import
com.google.appinventor.components.runtime.errors.YailRuntimeError
;
import
gnu.math.DFloNum
;
import
gnu.math.IntNum
;
import
junit.framework.Assert
;
import
junit.framework.TestCase
;
import
kawa.standard.Scheme
;
...
...
@@ -22,34 +20,19 @@ import kawa.standard.Scheme;
*
* @author markf@google.com (Mark Friedman)
*/
public
class
YailEvalTest
extends
TestCase
{
Scheme
scheme
;
private
Scheme
scheme
;
private
static
final
String
YAIL_SCHEME_TESTS
=
TestUtils
.
APP_INVENTOR_ROOT_DIR
+
"/buildserver/tests/com/google/appinventor/buildserver/YailEvalTest.scm"
;
private
static
final
String
OPEN
=
"<<"
;
private
static
final
String
ID
=
":"
;
private
static
final
String
TAG
=
"@@"
;
private
static
final
String
RESULT
=
"=="
;
private
static
final
String
CLOSE
=
">>"
;
private
static
final
String
SUCCESS
=
"Success"
;
private
static
final
String
FAILURE
=
"Failure"
;
private
static
final
String
ESCAPE
=
"&"
;
private
static
final
String
ENCODED_ESCAPE
=
"&0"
;
private
static
final
String
ENCODED_OPEN
=
"&1"
;
private
static
final
String
ENCODED_CLOSE
=
"&2"
;
@Override
public
void
setUp
()
throws
Exception
{
scheme
=
new
Scheme
();
String
yailRuntimeLibrary
=
Compiler
.
getResource
(
Compiler
.
YAIL_RUNTIME
);
String
yailSchemeTests
=
YAIL_SCHEME_TESTS
;
try
{
scheme
.
eval
(
"(load \""
+
yailRuntimeLibrary
+
"\")"
);
scheme
.
eval
(
"(load \""
+
yailSchemeTests
+
"\")"
);
scheme
.
eval
(
"(load \""
+
YAIL_SCHEME_TESTS
+
"\")"
);
scheme
.
eval
(
"(set! *testing* #t)"
);
}
catch
(
Exception
e
)
{
throw
e
;
...
...
@@ -360,7 +343,7 @@ public class YailEvalTest extends TestCase {
}
public
void
deepCopyTest
()
throws
Throwable
{
public
void
testDeepCopy
()
throws
Throwable
{
// check that yail-list-copy does a deep copy
String
schemeInputString
=
"(begin "
+
"(define list1 (make-yail-list (make-yail-list \"a\" \"b\") \"c\" \"d\" ))"
+
...
...
@@ -1094,15 +1077,9 @@ public class YailEvalTest extends TestCase {
String
expression
=
"("
+
funName
+
" "
+
args
[
i
]
+
")"
;
Object
result
=
scheme
.
eval
(
expression
);
if
(
result
instanceof
DFloNum
)
{
Assert
.
assertEquals
(
expression
,
vals
[
i
],
((
DFloNum
)
result
).
doubleValue
(),
DELTA
);
assertEquals
(
expression
,
vals
[
i
],
((
DFloNum
)
result
).
doubleValue
(),
DELTA
);
}
else
{
Assert
.
assertEquals
(
expression
,
vals
[
i
],
(
Double
)
result
,
DELTA
);
assertEquals
(
expression
,
vals
[
i
],
(
Double
)
result
,
DELTA
);
}
}
}
...
...
@@ -1147,9 +1124,9 @@ public class YailEvalTest extends TestCase {
}
// These constant definitions make the below tests more readable.
static
final
double
PI
=
Math
.
PI
;
static
final
double
PI_2
=
PI
/
2
;
static
final
double
PI_4
=
PI
/
4
;
private
static
final
double
PI
=
Math
.
PI
;
private
static
final
double
PI_2
=
PI
/
2
;
private
static
final
double
PI_4
=
PI
/
4
;
public
void
testDegreesToRadians
()
throws
Throwable
{
double
[]
args
=
{
-
45
,
0
,
45
,
90
,
270
,
360
,
720
};
...
...
@@ -1170,9 +1147,7 @@ public class YailEvalTest extends TestCase {
throws
Throwable
{
for
(
int
i
=
0
;
i
<
args1
.
length
;
i
++)
{
String
expression
=
"("
+
funName
+
" "
+
args1
[
i
]
+
" "
+
args2
[
i
]
+
")"
;
Assert
.
assertEquals
(
vals
[
i
],
((
DFloNum
)
scheme
.
eval
(
expression
)).
doubleValue
(),
DELTA
);
assertEquals
(
vals
[
i
],
((
DFloNum
)
scheme
.
eval
(
expression
)).
doubleValue
(),
DELTA
);
}
}
...
...
appinventor/components/src/com/google/appinventor/components/runtime/Clock.java
View file @
8bce6ff5
...
...
@@ -47,7 +47,7 @@ import android.app.TimePickerDialog;
nonVisible
=
true
,
iconName
=
"images/clock.png"
)
@SimpleObject
public
final
class
Clock
extends
AndroidNonvisibleComponent
public
class
Clock
extends
AndroidNonvisibleComponent
implements
Component
,
AlarmHandler
,
OnStopListener
,
OnResumeListener
,
OnDestroyListener
,
Deleteable
{
private
static
final
int
DEFAULT_INTERVAL
=
1000
;
// ms
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment