Skip to content

Commit

Permalink
Merge pull request ElektraInitiative#3725 from aaronabebe/master
Browse files Browse the repository at this point in the history
[CM H1] added two small jna tests
  • Loading branch information
tucek authored Mar 29, 2021
2 parents ebc9d20 + f20f1fc commit 846d37f
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 18 deletions.
2 changes: 1 addition & 1 deletion doc/news/_preparation_next_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ _(@tucek)_
## Tests
- <<TODO>>
- Added small test for jna Return plugin (`Return.java`), `KeyNameIterator.java` _(@aaronabebe)_
- <<TODO>>
- <<TODO>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.libelektra.exception.model.WarningEntryTest;
import org.libelektra.plugin.ReturnTest;

@RunWith (Suite.class)
@SuiteClasses ({ KeySetTest.class, KeyTest.class, KDBTest.class, ExceptionMapperTest.class, KDBExceptionTest.class, PluginLoaderIT.class,
WarningEntryTest.class, ExceptionMapperIT.class, GOptsTest.class })
@SuiteClasses ({ KeySetTest.class, KeyTest.class, KeyNameIteratorTest.class, KDBTest.class, ExceptionMapperTest.class,
KDBExceptionTest.class, PluginLoaderIT.class, WarningEntryTest.class, ReturnTest.class, ExceptionMapperIT.class,
GOptsTest.class })
public class AllTests
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.libelektra;

import static org.junit.Assert.*;

import java.util.Iterator;
import org.junit.Test;

public class KeyNameIteratorTest
{

static final String KEY_1_NAME = "/key_test/1/key_name";
static final String KEY_1_NAME_PART_1 = "\u0001";
static final String KEY_1_NAME_PART_2 = "key_test";
static final String KEY_1_NAME_PART_3 = "1";
static final String KEY_1_NAME_PART_4 = "key_name";
static final String KEY_1_VALUE = "key_value_1";

@Test public void test_keyNameIteratorHasNext_shouldPass ()
{
final Key key = Key.create (KEY_1_NAME, KEY_1_VALUE);
final Iterator<String> iterator = key.iterator ();
assertTrue (iterator.hasNext ());
assertEquals (KEY_1_NAME_PART_1, iterator.next ());
assertTrue (iterator.hasNext ());
assertEquals (KEY_1_NAME_PART_2, iterator.next ());
assertTrue (iterator.hasNext ());
assertEquals (KEY_1_NAME_PART_3, iterator.next ());
assertTrue (iterator.hasNext ());
assertEquals (KEY_1_NAME_PART_4, iterator.next ());
assertFalse (iterator.hasNext ());
}

@Test (expected = UnsupportedOperationException.class) public void test_keyNameIteratorDelete_shouldPass ()
{
final Key key = Key.create (KEY_1_NAME, KEY_1_VALUE);
final Iterator<String> iterator = key.iterator ();
assertTrue (iterator.hasNext ());
iterator.remove ();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,6 @@ public class KeyTest
assertEquals (key.get (), key2.get ()); // equal pointer
}

@Test public void test_keyNameIterator_shouldPass ()
{
final Key key = Key.create (KEY_1_NAME, KEY_1_VALUE);
final Iterator<String> iterator = key.iterator ();
assertTrue (iterator.hasNext ());
assertEquals (KEY_1_NAME_PART_1, iterator.next ());
assertTrue (iterator.hasNext ());
assertEquals (KEY_1_NAME_PART_2, iterator.next ());
assertTrue (iterator.hasNext ());
assertEquals (KEY_1_NAME_PART_3, iterator.next ());
assertTrue (iterator.hasNext ());
assertEquals (KEY_1_NAME_PART_4, iterator.next ());
assertFalse (iterator.hasNext ());
}

@Test public void test_keyWithBooleanValue_shouldPass ()
{
final Key key = Key.create (KEY_2_NAME, KEY_2_VALUE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.libelektra.plugin;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;
import org.libelektra.Key;
import org.libelektra.KeySet;

public class ReturnTest
{

static final String ERROR_KEY_NAME = "/temporary/errorkey";
static final String ERROR_KEY_VALUE = "error";

private Return returnPlugin;
private Key errorKey;

@Before public void setup ()
{
returnPlugin = new Return ();
errorKey = Key.create (ERROR_KEY_NAME, ERROR_KEY_VALUE);
}

@Test public void test_returnOpen_shouldBeCode0 ()
{
KeySet config = returnPlugin.getConfig ();
int open = returnPlugin.open (config, errorKey);
assertEquals (0, open);
}

@Test public void test_returnGet_ShouldBeCode10 ()
{
KeySet config = returnPlugin.getConfig ();
int open = returnPlugin.get (config, errorKey);
assertEquals (10, open);
}

@Test public void test_returnSet_ShouldBeCode20 ()
{
KeySet config = returnPlugin.getConfig ();
int open = returnPlugin.set (config, errorKey);
assertEquals (20, open);
}

@Test public void test_returnError_ShouldBeCode30 ()
{
KeySet config = returnPlugin.getConfig ();
int open = returnPlugin.error (config, errorKey);
assertEquals (30, open);
}

@Test public void test_returnClose_ShouldBeCode0 ()
{
int open = returnPlugin.close (errorKey);
assertEquals (0, open);
}

@Test public void test_returnGetName_ShouldBeReturn ()
{
assertEquals (Return.PLUGIN_NAME, returnPlugin.getName ());
}
}

0 comments on commit 846d37f

Please sign in to comment.