END_TEST /******************************************************************************* * create list from enumerator */ START_TEST(test_create_from_enumerator) { enumerator_t *enumerator, *enumerator_other; linked_list_t *other; intptr_t x, y; int count = 0; enumerator = list->create_enumerator(list); other = linked_list_create_from_enumerator(enumerator); ck_assert_int_eq(other->get_count(list), 5); enumerator = list->create_enumerator(list); enumerator_other = other->create_enumerator(other); while (enumerator->enumerate(enumerator, &x) && enumerator_other->enumerate(enumerator_other, &y)) { ck_assert_int_eq(x, y); count++; } ck_assert_int_eq(count, 5); enumerator_other->destroy(enumerator_other); enumerator->destroy(enumerator); other->destroy(other); }
/** * Convert the native C strings in the enumerator to a Java String array. * The given enumerator gets destroyed. */ static jobjectArray string_array_create(JNIEnv *env, enumerator_t *enumerator) { linked_list_t *list; jobjectArray jarray; jstring jstring; char *native; jclass cls; int i = 0; cls = (*env)->FindClass(env, "java/lang/String"); list = linked_list_create_from_enumerator(enumerator); jarray = (*env)->NewObjectArray(env, list->get_count(list), cls, NULL); if (!jarray) { goto failed; } enumerator = list->create_enumerator(list); while (enumerator->enumerate(enumerator, (void**)&native)) { jstring = (*env)->NewStringUTF(env, native); if (!jstring) { enumerator->destroy(enumerator); goto failed; } (*env)->SetObjectArrayElement(env, jarray, i++, jstring); } enumerator->destroy(enumerator); list->destroy(list); return jarray; failed: androidjni_exception_occurred(env); list->destroy(list); return NULL; }