Commits

shuerhaaken committed 920846a

add faulty test for labels in C

Comments (0)

Files changed (3)

bindings/c/taginfo_c.cc

     const Info *i = reinterpret_cast<const Info *>(info);
     StringList list = i->get_track_labels_list();
     labels = NULL;
-    *labels_length = list.size();
-    *labels = (char*) malloc(list.size() * sizeof(char*));
+    *labels_length = 0;
+    if(list.isEmpty())
+        cout << "list not there"  << endl;
+    int len = list.size();
+    labels = (char**)malloc(len * sizeof(char*));
     int j = 0;
     for(StringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
-        labels[j] = ::strdup( (*it).toCString(true));
+        labels[j] = ::strdup( (*it).toCString(false));
         j++;
     }
+    *labels_length = len;
 }
 void taginfo_info_set_track_labels(TagInfo_Info *info,
                                    const char** labels, int labels_length) {
     StringList list = StringList();
     for(int j = 0; j < labels_length; j++) {
         if(labels[j]) {
-            list.append(labels[j]);
+            list.append(::strdup(labels[j]));
         }
     }
     i->set_track_labels_list(list);
     const Info *i = reinterpret_cast<const Info *>(info);
     StringList list = i->get_album_labels_list();
     labels = NULL;
-    *labels_length = list.size();
-    *labels = (char*) malloc(list.size() * sizeof(char*));
+    *labels_length = 0;
+    if(list.isEmpty())
+        cout << "list not there"  << endl;
+    int len = list.size();
+    labels = (char**)malloc(len * sizeof(char*));
     int j = 0;
     for(StringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
-        labels[j] = ::strdup( (*it).toCString(true));
+        labels[j] = ::strdup( (*it).toCString(false));
         j++;
     }
+    *labels_length = len;
 }
 void taginfo_info_set_album_labels(TagInfo_Info *info,
-                                   const char* labels, int labels_length) {
+                                   const char** labels, int labels_length) {
     Info *i = reinterpret_cast<Info *>(info);
     StringList list = StringList();
     for(int j = 0; j < labels_length; j++) {
         if(labels[j]) {
-            list.append(labels[j]);
+            list.append(::strdup(labels[j]));
         }
     }
     i->set_album_labels_list(list);
 }
 
 void taginfo_info_get_artist_labels(const TagInfo_Info *info,
-                                    char** labels, int *labels_length) {
+                                    char** labels, int * labels_length) {
     const Info *i = reinterpret_cast<const Info *>(info);
     StringList list = i->get_artist_labels_list();
     labels = NULL;
-    *labels_length = list.size();
-    *labels = (char*) malloc(list.size() * sizeof(char*));
+    *labels_length = 0;
+    if(list.isEmpty())
+        cout << "list not there"  << endl;
+    int len = list.size();
+    labels = (char**)malloc(sizeof(char*) * len);
+//    labels = (char**)malloc(len * sizeof(char*));
     int j = 0;
     for(StringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
-        labels[j] = ::strdup( (*it).toCString(true));
+        cout << "label artist: " << (*it).toCString(false) << endl;
+        labels[j] = ::strdup( (*it).toCString(false));
+        cout << "label artist cstr: " << labels[j] << endl;
         j++;
     }
+    *labels_length = len;
 }
 void taginfo_info_set_artist_labels(TagInfo_Info *info,
-                                    const char* labels, int labels_length) {
+                                    const char** labels, int labels_length) {
     Info *i = reinterpret_cast<Info *>(info);
     StringList list = StringList();
     for(int j = 0; j < labels_length; j++) {
         if(labels[j]) {
-            list.append(labels[j]);
+            list.append(::strdup(labels[j]));
         }
     }
     i->set_artist_labels_list(list);

bindings/c/taginfo_c.h

 void taginfo_info_get_track_labels(const TagInfo_Info *info,
                                    char** data, int *data_length);
 void taginfo_info_set_track_labels(TagInfo_Info *info,
-                                   const char* data, int data_length);
+                                   const char** data, int data_length);
 
 void taginfo_info_get_album_labels(const TagInfo_Info *info,
                                    char** data, int *data_length);
 void taginfo_info_set_album_labels(TagInfo_Info *info,
-                                   const char* data, int data_length);
+                                   const char** data, int data_length);
 
 void taginfo_info_get_artist_labels(const TagInfo_Info *info,
                                     char** data, int *data_length);
 void taginfo_info_set_artist_labels(TagInfo_Info *info,
-                                    const char* data, int data_length);
+                                    const char** data, int data_length);
 
 BOOL taginfo_info_can_handle_image(const TagInfo_Info *info);
 BOOL taginfo_info_get_image(const TagInfo_Info *info,

tests/ctest_write/main.c

 }
 
 
+int check_list_equal(const char** labels, int labels_length, const char** out_labels, int out_labels_length) {
+    if(labels_length != out_labels_length)
+        return 0; // not equal
+printf("++1\n");
+    int i = 0;
+printf("++2\n");
+    for(; i < labels_length; i++) {
+printf("++2.1\n");
+        if(!labels)
+            printf("alarm 1\n");
+        if(!out_labels)
+            printf("alarm 2\n");
+        char* first = labels[i];
+        char* second = out_labels[i];
+        printf("++2.2 %s\n", first);
+        printf("++2.3 %s\n", second);
+        if(strcmp(labels[i], out_labels[i]) != 0)
+            return 0; // not equal
+printf("++3\n");
+    }
+printf("++4\n");
+    return 1; //EQUAL
+}
+
 int main(void)
 {
     TagInfo_Info *info;
     
     if(info == NULL)
         return 1; //EXIT_FAILURE
-    
     taginfo_info_set_title(info, TESTTITLE);
+    int labels_length = 2;
+    char** labels = malloc(labels_length * sizeof(char*));
+    labels[0] = strdup("label 1 äöü");
+    labels[1] = strdup("label 2 äéü");
+    taginfo_info_set_artist_labels(info, labels, labels_length);
     taginfo_info_write(info);
     taginfo_info_free(info);
-    
     info = taginfo_info_factory_make(target);
     if(taginfo_info_read(info)) {
         char* name = taginfo_info_get_title(info);
-        if(strcmp(name, TESTTITLE) == 0) {
+        
+        int out_labels_length = 0;
+        char** out_labels;
+        taginfo_info_get_artist_labels(info, out_labels, &out_labels_length);
+printf("out_labels_length: %d\n", out_labels_length);
+printf("out_labels[0]: %s\n", out_labels[0]);
+
+        if(strcmp(name, TESTTITLE) == 0 &&
+           check_list_equal(labels, labels_length, out_labels, out_labels_length)) {
+            
             free(name);
             taginfo_info_free(info);
             return 0; //EXIT_SUCCESS