| 1 |
sysadm |
1.3 |
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
| 2 |
|
|
/*
|
| 3 |
|
|
* test_article_favor
|
| 4 |
|
|
* - tester for data model and basic operations of user favorite articles
|
| 5 |
|
|
*
|
| 6 |
sysadm |
1.4 |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com>
|
| 7 |
sysadm |
1.3 |
*/
|
| 8 |
sysadm |
1.1 |
|
| 9 |
sysadm |
1.5 |
#ifdef HAVE_CONFIG_H
|
| 10 |
|
|
#include "config.h"
|
| 11 |
|
|
#endif
|
| 12 |
|
|
|
| 13 |
sysadm |
1.1 |
#include "article_favor.h"
|
| 14 |
|
|
#include <stdio.h>
|
| 15 |
|
|
|
| 16 |
|
|
int main(int argc, char *argv[])
|
| 17 |
|
|
{
|
| 18 |
|
|
ARTICLE_FAVOR favor;
|
| 19 |
|
|
int32_t aid;
|
| 20 |
|
|
int i;
|
| 21 |
|
|
int ret = 0;
|
| 22 |
|
|
|
| 23 |
|
|
article_favor_load(0, &favor, 0);
|
| 24 |
|
|
|
| 25 |
|
|
printf("Test #1\n");
|
| 26 |
|
|
|
| 27 |
|
|
for (i = MAX_FAVOR_AID_INC_CNT * 3; i > 0; i--)
|
| 28 |
|
|
{
|
| 29 |
|
|
if (i % MAX_FAVOR_AID_INC_CNT == 0 || i % MAX_FAVOR_AID_INC_CNT == MAX_FAVOR_AID_INC_CNT / 2)
|
| 30 |
|
|
{
|
| 31 |
|
|
printf("Base cnt = %d, Inc cnt = %d\n", favor.aid_base_cnt, favor.aid_inc_cnt);
|
| 32 |
|
|
}
|
| 33 |
|
|
|
| 34 |
|
|
aid = i * 5 + 7;
|
| 35 |
|
|
if (article_favor_check(aid, &favor) != 0)
|
| 36 |
|
|
{
|
| 37 |
|
|
printf("article_favor_check(%d) != 0\n", aid);
|
| 38 |
|
|
break;
|
| 39 |
|
|
}
|
| 40 |
|
|
if (article_favor_set(aid, &favor, 1) != 1)
|
| 41 |
|
|
{
|
| 42 |
|
|
printf("article_favor_set(%d, 1) != 1\n", aid);
|
| 43 |
|
|
break;
|
| 44 |
|
|
}
|
| 45 |
|
|
if (article_favor_check(aid, &favor) != 1)
|
| 46 |
|
|
{
|
| 47 |
|
|
printf("article_favor_check(%d) != 1\n", aid);
|
| 48 |
|
|
break;
|
| 49 |
|
|
}
|
| 50 |
|
|
if ((ret = article_favor_set(aid, &favor, 0)) != 2)
|
| 51 |
|
|
{
|
| 52 |
|
|
printf("article_favor_set(%d, 0) != 2, ret = %d\n", aid, ret);
|
| 53 |
|
|
break;
|
| 54 |
|
|
}
|
| 55 |
|
|
|
| 56 |
|
|
if (article_favor_check(aid, &favor) != 0)
|
| 57 |
|
|
{
|
| 58 |
|
|
printf("article_favor_check(%d) != 0\n", aid);
|
| 59 |
|
|
break;
|
| 60 |
|
|
}
|
| 61 |
|
|
}
|
| 62 |
|
|
|
| 63 |
|
|
printf("Base cnt = %d, Inc cnt = %d\n", favor.aid_base_cnt, favor.aid_inc_cnt);
|
| 64 |
|
|
|
| 65 |
|
|
printf("Test #2\n");
|
| 66 |
|
|
|
| 67 |
|
|
article_favor_merge_inc(&favor);
|
| 68 |
|
|
|
| 69 |
|
|
printf("Base cnt = %d, Inc cnt = %d\n", favor.aid_base_cnt, favor.aid_inc_cnt);
|
| 70 |
|
|
|
| 71 |
|
|
for (i = MAX_FAVOR_AID_INC_CNT * 3; i > 0; i--)
|
| 72 |
|
|
{
|
| 73 |
|
|
if (i % MAX_FAVOR_AID_INC_CNT == 0 || i % MAX_FAVOR_AID_INC_CNT == MAX_FAVOR_AID_INC_CNT / 2)
|
| 74 |
|
|
{
|
| 75 |
|
|
printf("Base cnt = %d, Inc cnt = %d\n", favor.aid_base_cnt, favor.aid_inc_cnt);
|
| 76 |
|
|
}
|
| 77 |
|
|
|
| 78 |
|
|
aid = i * 5 + 7;
|
| 79 |
|
|
if (article_favor_check(aid, &favor) != 0)
|
| 80 |
|
|
{
|
| 81 |
|
|
printf("article_favor_check(%d) != 0\n", aid);
|
| 82 |
|
|
break;
|
| 83 |
|
|
}
|
| 84 |
|
|
|
| 85 |
|
|
if (article_favor_set(aid, &favor, 1) != 1)
|
| 86 |
|
|
{
|
| 87 |
|
|
printf("article_favor_set(%d, 1) != 1\n", aid);
|
| 88 |
|
|
break;
|
| 89 |
|
|
}
|
| 90 |
|
|
if (article_favor_check(aid, &favor) != 1)
|
| 91 |
|
|
{
|
| 92 |
|
|
printf("article_favor_check(%d) != 1\n", aid);
|
| 93 |
|
|
break;
|
| 94 |
|
|
}
|
| 95 |
|
|
}
|
| 96 |
|
|
|
| 97 |
|
|
printf("Base cnt = %d, Inc cnt = %d\n", favor.aid_base_cnt, favor.aid_inc_cnt);
|
| 98 |
|
|
|
| 99 |
|
|
printf("Test #3\n");
|
| 100 |
|
|
|
| 101 |
|
|
article_favor_merge_inc(&favor);
|
| 102 |
|
|
|
| 103 |
|
|
printf("Base cnt = %d, Inc cnt = %d\n", favor.aid_base_cnt, favor.aid_inc_cnt);
|
| 104 |
|
|
|
| 105 |
|
|
for (i = MAX_FAVOR_AID_INC_CNT * 3; i > 0; i--)
|
| 106 |
|
|
{
|
| 107 |
|
|
if (i % MAX_FAVOR_AID_INC_CNT == 0 || i % MAX_FAVOR_AID_INC_CNT == MAX_FAVOR_AID_INC_CNT / 2)
|
| 108 |
|
|
{
|
| 109 |
|
|
printf("Base cnt = %d, Inc cnt = %d\n", favor.aid_base_cnt, favor.aid_inc_cnt);
|
| 110 |
|
|
}
|
| 111 |
|
|
|
| 112 |
|
|
aid = i * 5 + 7;
|
| 113 |
sysadm |
1.2 |
if (article_favor_check(aid, &favor) != 1)
|
| 114 |
|
|
{
|
| 115 |
|
|
printf("article_favor_check(%d) != 1\n", aid);
|
| 116 |
|
|
break;
|
| 117 |
|
|
}
|
| 118 |
|
|
|
| 119 |
sysadm |
1.1 |
if (article_favor_set(aid, &favor, 1) != 0)
|
| 120 |
|
|
{
|
| 121 |
|
|
printf("article_favor_set(%d, 1) != 0\n", aid);
|
| 122 |
|
|
break;
|
| 123 |
|
|
}
|
| 124 |
|
|
|
| 125 |
|
|
if (article_favor_check(aid, &favor) != 1)
|
| 126 |
|
|
{
|
| 127 |
|
|
printf("article_favor_check(%d) != 1\n", aid);
|
| 128 |
|
|
break;
|
| 129 |
|
|
}
|
| 130 |
|
|
|
| 131 |
|
|
if (article_favor_set(aid, &favor, 0) != 1)
|
| 132 |
|
|
{
|
| 133 |
|
|
printf("article_favor_set(%d, 0) != 1\n", aid);
|
| 134 |
|
|
break;
|
| 135 |
|
|
}
|
| 136 |
|
|
|
| 137 |
|
|
if (article_favor_check(aid, &favor) != 0)
|
| 138 |
|
|
{
|
| 139 |
|
|
printf("article_favor_check(%d) != 0\n", aid);
|
| 140 |
|
|
break;
|
| 141 |
|
|
}
|
| 142 |
|
|
}
|
| 143 |
|
|
|
| 144 |
|
|
printf("Base cnt = %d, Inc cnt = %d\n", favor.aid_base_cnt, favor.aid_inc_cnt);
|
| 145 |
|
|
|
| 146 |
|
|
printf("Test #4\n");
|
| 147 |
|
|
|
| 148 |
|
|
article_favor_merge_inc(&favor);
|
| 149 |
|
|
|
| 150 |
|
|
printf("Base cnt = %d, Inc cnt = %d\n", favor.aid_base_cnt, favor.aid_inc_cnt);
|
| 151 |
|
|
|
| 152 |
|
|
article_favor_unload(&favor);
|
| 153 |
|
|
|
| 154 |
|
|
return 0;
|
| 155 |
|
|
}
|