[vlma-devel] commit: Test Program#isTimeToPlay(). (Adrien Grand )
git version control
git at videolan.org
Fri Apr 3 22:43:52 CEST 2009
vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Fri Apr 3 22:40:36 2009 +0200| [ca11f7724723a32314cd566f0dfada7ee2eda2f8] | committer: Adrien Grand
Test Program#isTimeToPlay().
> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=ca11f7724723a32314cd566f0dfada7ee2eda2f8
---
.../main/java/org/videolan/vlma/model/Program.java | 6 +-
.../java/org/videolan/vlma/model/ProgramTest.java | 85 ++++++++++++++++++++
2 files changed, 88 insertions(+), 3 deletions(-)
diff --git a/vlma-api/src/main/java/org/videolan/vlma/model/Program.java b/vlma-api/src/main/java/org/videolan/vlma/model/Program.java
index 50cdbb2..0e65ee3 100644
--- a/vlma-api/src/main/java/org/videolan/vlma/model/Program.java
+++ b/vlma-api/src/main/java/org/videolan/vlma/model/Program.java
@@ -124,7 +124,7 @@ public final class Program implements Serializable {
group = null;
name = "";
setLiveInterval(0);
- setLiveRepetitions(1);
+ setLiveRepetitions(-1);
setLiveLength(-1);
liveStart = new Date();
setIp(null);
@@ -314,9 +314,9 @@ public final class Program implements Serializable {
*/
public boolean isTimeToPlay() {
long now = System.currentTimeMillis();
- long startTime = getLiveStart().getTime();
+ long startTime = liveStart.getTime();
- return (startTime - now >= 0) &&
+ return (now - startTime >= 0) &&
(liveLength < 0 || now - startTime <= liveLength ||
(liveLength > 0 && liveInterval > 0 &&
(now - startTime) % liveInterval <= liveLength &&
diff --git a/vlma-api/src/test/java/org/videolan/vlma/model/ProgramTest.java b/vlma-api/src/test/java/org/videolan/vlma/model/ProgramTest.java
new file mode 100644
index 0000000..6b186ec
--- /dev/null
+++ b/vlma-api/src/test/java/org/videolan/vlma/model/ProgramTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2008 the VideoLAN team
+ *
+ * This file is part of VLMa.
+ *
+ * VLMa is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * VLMa is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with VLMa. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package org.videolan.vlma.model;
+
+import static org.junit.Assert.*;
+
+import java.util.Date;
+
+import org.junit.Test;
+
+public class ProgramTest {
+
+ @Test
+ public void testIsTimeToPlayOnInstantiation() {
+ Program program = new Program();
+ assertTrue(program.isTimeToPlay());
+ }
+
+ @Test
+ public void testNotStartedYet() {
+ Program program = new Program();
+ program.setLiveStart(new Date(System.currentTimeMillis() + 10000));
+ assertFalse(program.isTimeToPlay());
+ }
+
+ @Test
+ public void testAlreadyStarted() {
+ Program program = new Program();
+ program.setLiveStart(new Date());
+ assertTrue(program.isTimeToPlay());
+ }
+
+ @Test
+ public void testLiveExpired() {
+ Program program = new Program();
+ program.setLiveStart(new Date(System.currentTimeMillis() - 1000));
+ program.setLiveLength(800);
+ assertFalse(program.isTimeToPlay());
+ }
+
+ @Test
+ public void testLiveNotExpiredYet() {
+ Program program = new Program();
+ program.setLiveStart(new Date(System.currentTimeMillis() - 1000));
+ program.setLiveLength(2000);
+ assertTrue(program.isTimeToPlay());
+ }
+
+ @Test
+ public void testInactiveSlot() {
+ Program program = new Program();
+ program.setLiveStart(new Date(System.currentTimeMillis() - 1000));
+ program.setLiveLength(600);
+ program.setLiveInterval(2000);
+ assertFalse(program.isTimeToPlay());
+ }
+
+ @Test
+ public void testActiveSlot() {
+ Program program = new Program();
+ program.setLiveStart(new Date(System.currentTimeMillis() - 1000));
+ program.setLiveLength(600);
+ program.setLiveInterval(900);
+ assertTrue(program.isTimeToPlay());
+ }
+
+}
More information about the vlma-devel
mailing list