about summary refs log tree commit diff stats
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/history.c283
-rw-r--r--src/tools/history.h45
2 files changed, 0 insertions, 328 deletions
diff --git a/src/tools/history.c b/src/tools/history.c
deleted file mode 100644
index def10feb..00000000
--- a/src/tools/history.c
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * history.c
- *
- * Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
- *
- * This file is part of Profanity.
- *
- * Profanity 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 3 of the License, or
- * (at your option) any later version.
- *
- * Profanity 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 Profanity.  If not, see <http://www.gnu.org/licenses/>.
- *
- * In addition, as a special exception, the copyright holders give permission to
- * link the code of portions of this program with the OpenSSL library under
- * certain conditions as described in each individual source file, and
- * distribute linked combinations including the two.
- *
- * You must obey the GNU General Public License in all respects for all of the
- * code used other than OpenSSL. If you modify file(s) with this exception, you
- * may extend this exception to your version of the file(s), but you are not
- * obligated to do so. If you do not wish to do so, delete this exception
- * statement from your version. If you delete this exception statement from all
- * source files in the program, then also delete it here.
- *
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include <glib.h>
-
-#include "history.h"
-
-struct history_session_t {
-    GList *items;
-    GList *sess_curr;
-    GList *sess_new;
-    GList *orig_curr;
-};
-
-struct history_t {
-    GList *items;
-    guint max_size;
-    struct history_session_t session;
-};
-
-static void _replace_history_with_session(History history);
-static gboolean _adding_new(History history);
-static void _reset_session(History history);
-static gboolean _has_session(History history);
-static void _remove_first(History history);
-static void _update_current_session_item(History history, char *item);
-static void _add_to_history(History history, char *item);
-static void _remove_last_session_item(History history);
-static void _replace_current_with_original(History history);
-static void _create_session(History history);
-static void _session_previous(History history);
-static void _session_next(History history);
-
-History
-history_new(unsigned int size)
-{
-    History new_history = malloc(sizeof(struct history_t));
-    new_history->items = NULL;
-    new_history->max_size = size;
-
-    _reset_session(new_history);
-
-    return new_history;
-}
-
-void
-history_append(History history, char *item)
-{
-    char *copied = "";
-    if (item != NULL) {
-        copied = strdup(item);
-    }
-
-    if (history->items == NULL) {
-        _add_to_history(history, copied);
-        return;
-    }
-
-    if (!_has_session(history)) {
-        if (g_list_length(history->items) == history->max_size) {
-            _remove_first(history);
-        }
-
-        _add_to_history(history, copied);
-
-    } else {
-        _update_current_session_item(history, copied);
-
-        if (_adding_new(history)) {
-            if (strcmp(history->session.sess_curr->data, "") == 0) {
-                _remove_last_session_item(history);
-            }
-
-            _replace_history_with_session(history);
-
-        } else {
-            _remove_last_session_item(history);
-
-            char *new = strdup(history->session.sess_curr->data);
-            history->session.items = g_list_append(history->session.items, new);
-
-            _replace_current_with_original(history);
-            _replace_history_with_session(history);
-        }
-    }
-}
-
-char *
-history_previous(History history, char *item)
-{
-    // no history
-    if (history->items == NULL) {
-        return NULL;
-    }
-
-    char *copied = "";
-    if (item != NULL) {
-        copied = strdup(item);
-    }
-
-    if (!_has_session(history)) {
-        _create_session(history);
-
-        // add the new item
-        history->session.items = g_list_append(history->session.items, copied);
-        history->session.sess_new = g_list_last(history->session.items);
-
-        char *result = strdup(history->session.sess_curr->data);
-        return result;
-    } else {
-        _update_current_session_item(history, copied);
-        _session_previous(history);
-    }
-
-    char *result = strdup(history->session.sess_curr->data);
-    return result;
-}
-
-char *
-history_next(History history, char *item)
-{
-    // no history, or no session, return NULL
-    if ((history->items == NULL) || (history->session.items == NULL)) {
-        return NULL;
-    }
-
-    if (g_list_next(history->session.sess_curr) == NULL) {
-        return NULL;
-    }
-
-    char *copied = "";
-    if (item != NULL) {
-        copied = strdup(item);
-    }
-
-    _update_current_session_item(history, copied);
-    _session_next(history);
-
-    char *result = strdup(history->session.sess_curr->data);
-    return result;
-}
-
-static void
-_replace_history_with_session(History history)
-{
-    g_list_free(history->items);
-    history->items = g_list_copy(history->session.items);
-
-    if (g_list_length(history->items) > history->max_size) {
-        _remove_first(history);
-    }
-
-    _reset_session(history);
-}
-
-static gboolean
-_adding_new(History history)
-{
-    return (history->session.sess_curr ==
-        g_list_last(history->session.items));
-}
-
-static void
-_reset_session(History history)
-{
-    history->session.items = NULL;
-    history->session.sess_curr = NULL;
-    history->session.sess_new = NULL;
-    history->session.orig_curr = NULL;
-}
-
-static gboolean
-_has_session(History history)
-{
-    return (history->session.items != NULL);
-}
-
-static void
-_remove_first(History history)
-{
-    GList *first = g_list_first(history->items);
-    char *first_item = first->data;
-    history->items = g_list_remove(history->items, first_item);
-}
-
-static void
-_update_current_session_item(History history, char *item)
-{
-    history->session.sess_curr->data = item;
-}
-
-static void
-_add_to_history(History history, char *item)
-{
-    history->items = g_list_append(history->items, item);
-}
-
-static void
-_remove_last_session_item(History history)
-{
-    history->session.items = g_list_reverse(history->session.items);
-    GList *first = g_list_first(history->session.items);
-    history->session.items =
-        g_list_remove(history->session.items, first->data);
-    history->session.items = g_list_reverse(history->session.items);
-}
-
-static void
-_replace_current_with_original(History history)
-{
-    history->session.sess_curr->data = strdup(history->session.orig_curr->data);
-}
-
-static void
-_create_session(History history)
-{
-    history->session.items = g_list_copy(history->items);
-    history->session.sess_curr = g_list_last(history->session.items);
-    history->session.orig_curr = g_list_last(history->items);
-}
-
-static void
-_session_previous(History history)
-{
-    history->session.sess_curr =
-        g_list_previous(history->session.sess_curr);
-    if (history->session.orig_curr == NULL)
-        history->session.orig_curr = g_list_last(history->items);
-    else
-        history->session.orig_curr =
-            g_list_previous(history->session.orig_curr);
-
-    if (history->session.sess_curr == NULL) {
-        history->session.sess_curr = g_list_first(history->session.items);
-        history->session.orig_curr = g_list_first(history->items);
-    }
-}
-
-static void
-_session_next(History history)
-{
-    history->session.sess_curr = g_list_next(history->session.sess_curr);
-    history->session.orig_curr = g_list_next(history->session.orig_curr);
-
-    if (history->session.sess_curr == NULL) {
-        history->session.sess_curr = g_list_last(history->session.items);
-        history->session.orig_curr = NULL;
-    }
-}
diff --git a/src/tools/history.h b/src/tools/history.h
deleted file mode 100644
index 7b334718..00000000
--- a/src/tools/history.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * history.h
- *
- * Copyright (C) 2012 - 2014 James Booth <boothj5@gmail.com>
- *
- * This file is part of Profanity.
- *
- * Profanity 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 3 of the License, or
- * (at your option) any later version.
- *
- * Profanity 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 Profanity.  If not, see <http://www.gnu.org/licenses/>.
- *
- * In addition, as a special exception, the copyright holders give permission to
- * link the code of portions of this program with the OpenSSL library under
- * certain conditions as described in each individual source file, and
- * distribute linked combinations including the two.
- *
- * You must obey the GNU General Public License in all respects for all of the
- * code used other than OpenSSL. If you modify file(s) with this exception, you
- * may extend this exception to your version of the file(s), but you are not
- * obligated to do so. If you do not wish to do so, delete this exception
- * statement from your version. If you delete this exception statement from all
- * source files in the program, then also delete it here.
- *
- */
-
-#ifndef HISTORY_H
-#define HISTORY_H
-
-typedef struct history_t  *History;
-
-History history_new(unsigned int size);
-char * history_previous(History history, char *item);
-char * history_next(History history, char *item);
-void history_append(History history, char *item);
-
-#endif
mitter James Booth <boothj5@gmail.com> 2013-01-12 23:10:56 +0000 Added jid datatype' href='/danisanti/profani-tty/commit/tests/test_jid.c?id=94bcf1889d5a07305784ff5bc92afffa71a5ccd3'>94bcf188 ^
07308673 ^
94bcf188 ^
1cc33cc4 ^
07308673 ^
94bcf188 ^

07308673 ^
94bcf188 ^
1cc33cc4 ^
07308673 ^
94bcf188 ^

07308673 ^
94bcf188 ^
1cc33cc4 ^
07308673 ^
94bcf188 ^

07308673 ^
94bcf188 ^
1cc33cc4 ^
07308673 ^
94bcf188 ^

07308673 ^
94bcf188 ^
1cc33cc4 ^
07308673 ^
94bcf188 ^

07308673 ^
94bcf188 ^
1cc33cc4 ^
07308673 ^
94bcf188 ^

07308673 ^
94bcf188 ^
1cc33cc4 ^
07308673 ^
94bcf188 ^

07308673 ^
94bcf188 ^
1cc33cc4 ^
07308673 ^
94bcf188 ^

07308673 ^
94bcf188 ^
1cc33cc4 ^
07308673 ^
94bcf188 ^

07308673 ^
3a22719b ^
8bdab23e ^
3a22719b ^
07308673 ^
3a22719b ^

07308673 ^
3a22719b ^
8bdab23e ^
3a22719b ^
07308673 ^
3a22719b ^

07308673 ^
d239a127 ^


07308673 ^




d239a127 ^

07308673 ^
d239a127 ^


07308673 ^




d239a127 ^

07308673 ^
d239a127 ^


07308673 ^




d239a127 ^

07308673 ^
d239a127 ^


07308673 ^




94bcf188 ^
e263e00a ^

















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185



                   
                   
 

                
                                                    
 
                                   
                        

 
                                                            
 
                                 
                        

 
                                                    
 
                                                       
                                                                   

 
                                                    
 
                                                       
                                                            

 
                                                            
 
                                                       
                                                        

 
                                                         
 
                                                       
                                                     

 
                                                          
 
                                                       
                                                        

 
                                                            
 
                                                
                                                            

 
                                                            
 
                                                
                                                     

 
                                                                    
 
                                                
                                                        

 
                                                                  
 
                                                
                                                        

 
                                                                      
 
                                                
                                   

 
                                                         
 
                                                
                                 

 
                                                             
 
                                                
                                      

 
                                                    
 
                                                
                                                            

 
                                                         
 
                                                
                                                     

 
                                                          
 
                                                
                                                        

 
                                               
 
                                                                                            
 
                                                                       

 
                                               
 
                                                                                            
 
                                                        

 
                                                


                                                                   




                                                                               

 
                                             


                                                                   




                                                                               

 
                                                       


                                                                             




                                                                                         

 
                                                  


                                                                 




                                                                             
 

















                                                                     
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>

#include "jid.h"

void create_jid_from_null_returns_null(void **state)
{
    Jid *result = jid_create(NULL);
    assert_null(result);
}

void create_jid_from_empty_string_returns_null(void **state)
{
    Jid *result = jid_create("");
    assert_null(result);
}

void create_jid_from_full_returns_full(void **state)
{
    Jid *result = jid_create("myuser@mydomain/laptop");
    assert_string_equal("myuser@mydomain/laptop", result->fulljid);
}

void create_jid_from_full_returns_bare(void **state)
{
    Jid *result = jid_create("myuser@mydomain/laptop");
    assert_string_equal("myuser@mydomain", result->barejid);
}

void create_jid_from_full_returns_resourcepart(void **state)
{
    Jid *result = jid_create("myuser@mydomain/laptop");
    assert_string_equal("laptop", result->resourcepart);
}

void create_jid_from_full_returns_localpart(void **state)
{
    Jid *result = jid_create("myuser@mydomain/laptop");
    assert_string_equal("myuser", result->localpart);
}

void create_jid_from_full_returns_domainpart(void **state)
{
    Jid *result = jid_create("myuser@mydomain/laptop");
    assert_string_equal("mydomain", result->domainpart);
}

void create_jid_from_full_nolocal_returns_full(void **state)
{
    Jid *result = jid_create("mydomain/laptop");
    assert_string_equal("mydomain/laptop", result->fulljid);
}

void create_jid_from_full_nolocal_returns_bare(void **state)
{
    Jid *result = jid_create("mydomain/laptop");
    assert_string_equal("mydomain", result->barejid);
}

void create_jid_from_full_nolocal_returns_resourcepart(void **state)
{
    Jid *result = jid_create("mydomain/laptop");
    assert_string_equal("laptop", result->resourcepart);
}

void create_jid_from_full_nolocal_returns_domainpart(void **state)
{
    Jid *result = jid_create("mydomain/laptop");
    assert_string_equal("mydomain", result->domainpart);
}

void create_jid_from_full_nolocal_returns_null_localpart(void **state)
{
    Jid *result = jid_create("mydomain/laptop");
    assert_null(result->localpart);
}

void create_jid_from_bare_returns_null_full(void **state)
{
    Jid *result = jid_create("myuser@mydomain");
    assert_null(result->fulljid);
}

void create_jid_from_bare_returns_null_resource(void **state)
{
    Jid *result = jid_create("myuser@mydomain");
    assert_null(result->resourcepart);
}

void create_jid_from_bare_returns_bare(void **state)
{
    Jid *result = jid_create("myuser@mydomain");
    assert_string_equal("myuser@mydomain", result->barejid);
}

void create_jid_from_bare_returns_localpart(void **state)
{
    Jid *result = jid_create("myuser@mydomain");
    assert_string_equal("myuser", result->localpart);
}

void create_jid_from_bare_returns_domainpart(void **state)
{
    Jid *result = jid_create("myuser@mydomain");
    assert_string_equal("mydomain", result->domainpart);
}

void create_room_jid_returns_room(void **state)
{
    Jid *result = jid_create_from_bare_and_resource("room@conference.domain.org", "myname");

    assert_string_equal("room@conference.domain.org", result->barejid);
}

void create_room_jid_returns_nick(void **state)
{
    Jid *result = jid_create_from_bare_and_resource("room@conference.domain.org", "myname");

    assert_string_equal("myname", result->resourcepart);
}

void create_with_slash_in_resource(void **state)
{
    Jid *result = jid_create("room@conference.domain.org/my/nick");

    assert_string_equal("room", result->localpart);
    assert_string_equal("conference.domain.org", result->domainpart);
    assert_string_equal("my/nick", result->resourcepart);
    assert_string_equal("room@conference.domain.org", result->barejid);
    assert_string_equal("room@conference.domain.org/my/nick", result->fulljid);
}

void create_with_at_in_resource(void **state)
{
    Jid *result = jid_create("room@conference.domain.org/my@nick");

    assert_string_equal("room", result->localpart);
    assert_string_equal("conference.domain.org", result->domainpart);
    assert_string_equal("my@nick", result->resourcepart);
    assert_string_equal("room@conference.domain.org", result->barejid);
    assert_string_equal("room@conference.domain.org/my@nick", result->fulljid);
}

void create_with_at_and_slash_in_resource(void **state)
{
    Jid *result = jid_create("room@conference.domain.org/my@nick/something");

    assert_string_equal("room", result->localpart);
    assert_string_equal("conference.domain.org", result->domainpart);
    assert_string_equal("my@nick/something", result->resourcepart);
    assert_string_equal("room@conference.domain.org", result->barejid);
    assert_string_equal("room@conference.domain.org/my@nick/something", result->fulljid);
}

void create_full_with_trailing_slash(void **state)
{
    Jid *result = jid_create("room@conference.domain.org/nick/");

    assert_string_equal("room", result->localpart);
    assert_string_equal("conference.domain.org", result->domainpart);
    assert_string_equal("nick/", result->resourcepart);
    assert_string_equal("room@conference.domain.org", result->barejid);
    assert_string_equal("room@conference.domain.org/nick/", result->fulljid);
}

void returns_fulljid_when_exists(void **state)
{
    Jid *jid = jid_create("localpart@domainpart/resourcepart");

    char *result = jid_fulljid_or_barejid(jid);

    assert_string_equal("localpart@domainpart/resourcepart", result);
}

void returns_barejid_when_fulljid_not_exists(void **state)
{
    Jid *jid = jid_create("localpart@domainpart");

    char *result = jid_fulljid_or_barejid(jid);

    assert_string_equal("localpart@domainpart", result);
}