TEST_F(atouintTest, RegularPositive) { const char *str = "305"; u_long actual; ASSERT_TRUE(atouint(str, &actual)); EXPECT_EQ(305, actual); }
void test_RegularPositive(void) { const char *str = "305"; u_long actual; TEST_ASSERT_TRUE(atouint(str, &actual)); TEST_ASSERT_EQUAL(305, actual); }
void test_IllegalChar(void) { const char *str = "50c3"; u_long actual; TEST_ASSERT_FALSE(atouint(str, &actual)); }
void test_Negative(void) { const char *str = "-1"; u_long actual; TEST_ASSERT_FALSE(atouint(str, &actual)); }
void test_PositiveOverflowBig(void) { const char *str = "8000000000"; u_long actual; TEST_ASSERT_FALSE(atouint(str, &actual)); }
void test_PositiveOverflowBoundary(void) { const char *str = "4294967296"; u_long actual; TEST_ASSERT_FALSE(atouint(str, &actual)); }
/* * readconf - read the configuration information out of the file we * were passed. Note that since the file is supposed to be * machine generated, we bail out at the first sign of trouble. */ static void readconf( FILE *fp, char *name ) { register int i; char *token[NUMTOK]; u_long intval[NUMTOK]; u_int flags; char buf[MAXLINESIZE]; char *bp; while (fgets(buf, MAXLINESIZE, fp) != NULL) { bp = buf; for (i = 0; i < NUMTOK; i++) { if ((token[i] = nexttoken(&bp)) == NULL) { msyslog(LOG_ERR, "tokenizing error in file `%s', quitting", name); resolver_exit(1); } } for (i = 1; i < NUMTOK - 1; i++) { if (!atouint(token[i], &intval[i])) { msyslog(LOG_ERR, "format error for integer token `%s', file `%s', quitting", token[i], name); resolver_exit(1); } } #if 0 /* paranoid checking - these are done in newpeer() */ if (intval[TOK_HMODE] != MODE_ACTIVE && intval[TOK_HMODE] != MODE_CLIENT && intval[TOK_HMODE] != MODE_BROADCAST) { msyslog(LOG_ERR, "invalid mode (%ld) in file %s", intval[TOK_HMODE], name); resolver_exit(1); } if (intval[TOK_VERSION] > NTP_VERSION || intval[TOK_VERSION] < NTP_OLDVERSION) { msyslog(LOG_ERR, "invalid version (%ld) in file %s", intval[TOK_VERSION], name); resolver_exit(1); } if (intval[TOK_MINPOLL] < ntp_minpoll || intval[TOK_MINPOLL] > NTP_MAXPOLL) { msyslog(LOG_ERR, "invalid MINPOLL value (%ld) in file %s", intval[TOK_MINPOLL], name); resolver_exit(1); } if (intval[TOK_MAXPOLL] < ntp_minpoll || intval[TOK_MAXPOLL] > NTP_MAXPOLL) { msyslog(LOG_ERR, "invalid MAXPOLL value (%ld) in file %s", intval[TOK_MAXPOLL], name); resolver_exit(1); } if ((intval[TOK_FLAGS] & ~(FLAG_PREFER | FLAG_NOSELECT | FLAG_BURST | FLAG_IBURST | FLAG_SKEY)) != 0) { msyslog(LOG_ERR, "invalid flags (%ld) in file %s", intval[TOK_FLAGS], name); resolver_exit(1); } #endif /* end paranoid checking */ flags = 0; if (intval[TOK_FLAGS] & FLAG_PREFER) flags |= CONF_FLAG_PREFER; if (intval[TOK_FLAGS] & FLAG_NOSELECT) flags |= CONF_FLAG_NOSELECT; if (intval[TOK_FLAGS] & FLAG_BURST) flags |= CONF_FLAG_BURST; if (intval[TOK_FLAGS] & FLAG_IBURST) flags |= CONF_FLAG_IBURST; #ifdef OPENSSL if (intval[TOK_FLAGS] & FLAG_SKEY) flags |= CONF_FLAG_SKEY; #endif /* OPENSSL */ /* * This is as good as we can check it. Add it in. */ addentry(token[TOK_HOSTNAME], (int)intval[TOK_NEEDED], (int)intval[TOK_TYPE], (int)intval[TOK_HMODE], (int)intval[TOK_VERSION], (int)intval[TOK_MINPOLL], (int)intval[TOK_MAXPOLL], flags, (int)intval[TOK_TTL], intval[TOK_KEYID], token[TOK_KEYSTR]); } }
TEST_F(atouintTest, IllegalChar) { const char *str = "50c3"; u_long actual; ASSERT_FALSE(atouint(str, &actual)); }
TEST_F(atouintTest, Negative) { const char *str = "-1"; u_long actual; ASSERT_FALSE(atouint(str, &actual)); }
TEST_F(atouintTest, PositiveOverflowBig) { const char *str = "8000000000"; u_long actual; ASSERT_FALSE(atouint(str, &actual)); }
TEST_F(atouintTest, PositiveOverflowBoundary) { const char *str = "4294967296"; u_long actual; ASSERT_FALSE(atouint(str, &actual)); }