Skip to content

Commit

Permalink
Test case for time zone using DLL's local time format
Browse files Browse the repository at this point in the history
  • Loading branch information
bear101 committed Oct 18, 2024
1 parent 1749a22 commit fc68938
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Library/TeamTalkJNI/test/dk/bearware/TeamTalkTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.Vector;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -4519,6 +4524,35 @@ public void testUserAcountLastLogin() {
assertNotEquals(first_login_account.szLastLoginTime, second_login_account.szLastLoginTime);
}

@Test
public void testTimeZone() {
final String USERNAME = "tt_test", PASSWORD = "tt_test", NICKNAME = "jUnit - " + getTestMethodName();
int USERRIGHTS = UserRight.USERRIGHT_TRANSMIT_MEDIAFILE | UserRight.USERRIGHT_CREATE_TEMPORARY_CHANNEL;
makeUserAccount(NICKNAME, USERNAME, PASSWORD, USERRIGHTS);

SimpleDateFormat fmt = new SimpleDateFormat("yyyy/MM/dd HH:mm");
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.set(1970, Calendar.JANUARY, 1, 0, 0, 0);

TeamTalkBase client = newClientInstance();
connect(client);
login(client, NICKNAME, USERNAME, PASSWORD);

UserAccount first_login_account = new UserAccount();
assertTrue("get account", client.getMyUserAccount(first_login_account));
assertEquals("must be 1970/01/01 in local time", fmt.format(calendar.getTime()), first_login_account.szLastLoginTime);

assertTrue("disconnect", client.disconnect());
connect(client);
login(client, NICKNAME, USERNAME, PASSWORD);

UserAccount second_login_account = new UserAccount();
assertTrue("get account again", client.getMyUserAccount(second_login_account));
Date logintime = fmt.parse(second_login_account.szLastLoginTime, new ParsePosition(0));
Date now = new Date();
assertEquals("time stamp match within 2 minutes", now.getTime() / 1000 , logintime.getTime() / 1000, 120);
}

/* cannot test output levels since a user is muted by sound system after decoding and callback.
@Test
Expand Down

0 comments on commit fc68938

Please sign in to comment.